LinuxCommandLibrary

mkdosfs

Create MS-DOS FAT filesystems

SYNOPSIS

mkdosfs [OPTIONS] DEVICE

PARAMETERS

DEVICE
    The special file corresponding to the block device or partition (e.g., /dev/sdb1, /dev/loop0) where the FAT file system will be created.

-c
    Instructs mkdosfs to check the device for bad blocks before proceeding with file system creation. This process can significantly increase the execution time.

-F <fat-type>
    Specifies the FAT type to be created. Valid arguments are 12, 16, or 32. If this option is omitted, mkdosfs will attempt to automatically determine the most suitable FAT type based on the size of the target device.

-v
    Enables verbose output, providing more detailed information about the file system creation process as it unfolds.

-n <volume-id>
    Sets the 32-bit hexadecimal volume ID for the new file system. An example format is 0x1234ABCD.

-L <volume-label>
    Assigns a volume label (up to 11 characters) to the new file system. Special characters are generally not supported, but spaces are usually allowed.

-s <sectors-per-cluster>
    Defines the number of disk sectors that constitute a single cluster. A cluster represents the smallest unit of disk space that can be allocated to a file.

-R <reserved-sectors>
    Specifies the count of reserved sectors located at the beginning of the FAT file system. Typical values are 1 for FAT12/16 and 32 for FAT32.

-f <number-of-fats>
    Determines the number of File Allocation Tables to be created. The default and common value for redundancy is 2.

-r <root-dir-entries>
    Sets the maximum number of root directory entries for FAT12/16 file systems. A common value is 512.

-I
    Disables the confirmation prompt, forcing the overwrite of existing data without warning. Use with extreme caution.

-C
    Causes mkdosfs to create the file system within a regular file, which is useful for generating disk images.

-h
    Displays a brief help message detailing command usage and exits.

DESCRIPTION

mkdosfs, also known as mkfs.fat, is a command-line utility used to create a FAT (File Allocation Table) file system on a specified device. This device can be a disk partition, a removable drive like a USB stick or SD card, or even a regular file intended to act as a disk image.

Its primary function is to initialize the necessary file system structures, including the boot sector, File Allocation Tables, and the root directory, making the medium ready for file storage. FAT file systems (FAT12, FAT16, FAT32) are widely recognized for their broad compatibility across various operating systems such as DOS, Windows, macOS, and Linux, as well as many embedded systems. This makes mkdosfs an indispensable tool for preparing portable storage media that need to be universally accessible.

CAVEATS

DANGER: Executing mkdosfs on a device will permanently erase all existing data on that device or partition. Always meticulously verify the target DEVICE to prevent unintentional data loss.

Operating on block devices (e.g., /dev/sdb1) generally requires root privileges.

FAT file systems inherently possess certain limitations, including the absence of built-in file permissions, case-insensitivity for filenames, and practical file size constraints, particularly with FAT12/16.

FILE SYSTEM TYPES AND COMMON USAGE

mkdosfs supports the creation of FAT12, FAT16, and FAT32 file systems. The selection of the FAT type is typically governed by the size of the partition and the required compatibility. FAT32 is generally recommended for partitions exceeding 2GB, whereas FAT12/16 may be utilized for smaller volumes, older systems, or highly specialized embedded applications.

While mkdosfs technically can format an entire physical drive (e.g., /dev/sdb), it is far more common and safer to format a specific partition (e.g., /dev/sdb1) that has been previously defined and created using a disk partitioning tool such as fdisk or parted. Always confirm the exact device path to avoid critical data loss.

HISTORY

mkdosfs is a core component of the dosfstools project, a collection of utilities designed for managing FAT file systems on Linux and other Unix-like operating systems. It functions as the specific implementation of the general mkfs command for the FAT file system type, developed to ensure robust compatibility with DOS and Windows environments.

SEE ALSO

mkfs(8), fsck.fat(8), dosfsck(8), mount(8), fdisk(8), parted(8)

Copied to clipboard