LinuxCommandLibrary

mkdosfs

Create MS-DOS FAT filesystems

SYNOPSIS

mkdosfs [ -a ] [ -b sector_number ] [ -c filename ] [ -C sectors ] [ -d drive_number ] [ -f number_of_FATs ] [ -F {12|16|32} ] [ -i volume_id ] [ -I ] [ -l filename ] [ -m message_file ] [ -n volume_label ] [ -o hidden_sectors ] [ -O creator_id ] [ -p first_sector ] [ -r root_entries ] [ -R number_reserved_sectors] [ -s sectors_per_cluster ] [ -S sector_size ] [ -v ] [ -w ] [ -V volume_label ] device [ blocks ]

PARAMETERS

-a
    Check the device for bad blocks before formatting.

-b sector_number
    Specify the backup boot sector location.

-c filename
    Read bad sector list from filename.

-C sectors
    Create a filesystem that occupies only sectors sectors.

-d drive_number
    Specify the BIOS drive number (for boot sector).

-f number_of_FATs
    Specify the number of FAT copies (default: 2).

-F {12|16|32}
    Specify the FAT type (12, 16, or 32).

-i volume_id
    Set the volume ID (hexadecimal).

-I
    Do not create a boot sector.

-l filename
    Read volume serial number and label from file.

-m message_file
    Specify a message file to embed in the boot sector.

-n volume_label
    Set the volume label (deprecated, use -V).

-o hidden_sectors
    Specify the number of hidden sectors.

-O creator_id
    Specify a creator id.

-p first_sector
    Specify where the partition starts.

-r root_entries
    Set number of root directory entries.

-R number_reserved_sectors
    Set number of reserved sectors.

-s sectors_per_cluster
    Specify sectors per cluster (must be a power of 2).

-S sector_size
    Specify sector size in bytes (usually 512, 1024, 2048 or 4096).

-v
    Verbose mode.

-w
    Only write the filesystem, do not check if this is really a device.

-V volume_label
    Set the volume label.

device
    The device to format (e.g., /dev/sda1).

blocks
    The number of blocks to format (optional).

DESCRIPTION

The mkdosfs command is used to create an MS-DOS filesystem under Linux. It's primarily used for creating FAT12, FAT16, and FAT32 filesystems on disk partitions or removable media like USB drives. It formats the specified device or partition and allows setting parameters like volume label, sectors per cluster, and filesystem size. It handles writing the boot sector, FAT tables, and root directory. It's a crucial tool for preparing storage devices for compatibility with older systems or for creating bootable media for BIOS-based computers. When using mkdosfs, be extremely careful to specify the correct device, as incorrect usage can result in data loss on the target device.

Note that the FAT32 filesystem has a maximum size limitation. While mkdosfs can create FAT32 filesystems, very large partitions might require other tools (like parted or gdisk) to handle the partitioning stage prior to using mkdosfs to create the filesystem itself. mkdosfs is typically included in the dosfstools package.

CAVEATS

Incorrect usage of mkdosfs can lead to permanent data loss. Always double-check the device specified. Ensure the target device is unmounted before formatting. Using improper parameters can result in an unusable filesystem.

DEFAULT FAT TYPE

If the -F option isn't specified, mkdosfs automatically chooses the FAT type based on the filesystem size. Generally, filesystems smaller than 32MB default to FAT12, those between 32MB and 2GB default to FAT16, and larger filesystems default to FAT32.

EXIT STATUS

mkdosfs exits with 0 on success. It exits with a non-zero value if errors occur during formatting.

HISTORY

mkdosfs evolved from earlier DOS filesystem utilities. Development initially focused on creating tools for Linux to interact with DOS-formatted media. As FAT standards matured (FAT16, FAT32), mkdosfs was updated to support these newer formats. Today, it's a stable tool maintained as part of the dosfstools package.

SEE ALSO

mount(8), umount(8), fsck.vfat(8), dosfslabel(1)

Copied to clipboard