mkfs.fat
Create a FAT filesystem
TLDR
Create a fat filesystem inside partition Y on device X
Create filesystem with a volume-name
Create filesystem with a volume-id
Use 5 instead of 2 file allocation tables
Specify filesystem type
SYNOPSIS
mkfs.fat [OPTIONS] DEVICE [BLOCKS]DEVICE specifies the block device (e.g., /dev/sdb1) to format.
BLOCKS (optional) specifies the number of blocks on the device.
PARAMETERS
-F fat-type
Specifies the FAT type (12, 16, or 32). If omitted, mkfs.fat attempts to detect the optimal type based on partition size.
-s sectors-per-cluster
Sets the number of logical sectors per cluster. This defines the cluster size (e.g., 8 for 4KB clusters with 512-byte sectors), affecting disk space efficiency and performance. Common values are powers of 2.
-S sector-size
Specifies the logical sector size in bytes (e.g., 512, 1024, 2048, 4096). Defaults to 512 bytes.
-n volume-name
Sets the volume label (up to 11 characters for FAT12/16, up to 11 bytes in Unicode for FAT32).
-v
Enables verbose output, displaying more information during the formatting process.
-I
Do not prompt for confirmation. Useful for scripting, but dangerous if the wrong device is specified.
-c
Checks for bad blocks on the device before creating the filesystem. This process can be time-consuming.
-r max-root-entries
Sets the maximum number of root directory entries for FAT12/16 filesystems. Ignored for FAT32.
-D
Creates a DOS 4.0 compatible filesystem. This might be needed for very old systems.
-m message-file
Specifies a file containing a message to be stored in the boot sector. Useful for custom boot messages.
DESCRIPTION
mkfs.fat is a command-line utility used to create, or format, a FAT (File Allocation Table) filesystem on a specified block device. It is part of the dosfstools package, which provides utilities for managing FAT filesystems under Linux. This command is essential for preparing storage devices like USB flash drives, SD cards, and external hard drives for use with operating systems that rely on FAT, including Windows, macOS, and various embedded systems, due to its widespread compatibility.
When mkfs.fat is executed, it initializes the device by writing the necessary filesystem structures: the boot sector, File Allocation Tables (FATs), the root directory, and the data area. It can create FAT12, FAT16, or FAT32 filesystems, automatically choosing the most appropriate type based on the partition size unless explicitly specified. The command offers various options to customize the filesystem properties, such as the volume label, cluster size, and the maximum number of root directory entries, allowing users to tailor the filesystem to specific needs or compatibility requirements. It effectively erases all existing data on the target device, making it crucial to ensure the correct device is selected before execution.
CAVEATS
Data Loss: Executing mkfs.fat will irrevocably erase all existing data on the target device. Always double-check the device path (e.g., /dev/sdb1) to avoid accidental data destruction on critical partitions.
Root Privileges: This command typically requires superuser (root) privileges to directly access and write to block devices. Use sudo or run as root.
Mounted Devices: Never run mkfs.fat on a device or partition that is currently mounted. Doing so can lead to filesystem corruption, data loss, or system instability. Always unmount the device first (e.g., sudo umount /dev/sdb1).
FAT Limitations: While widely compatible, FAT filesystems have limitations. FAT12 and FAT16 have significant partition size limits and file size limits (2GB or 4GB for FAT16). FAT32 supports larger partitions (up to 2TB) but still has a 4GB maximum file size limit for individual files. For larger files or partitions, other filesystems like exFAT, ext4, or NTFS might be more suitable.
USAGE EXAMPLES
Here are some common usage scenarios for mkfs.fat:
1. Basic FAT32 format:
sudo mkfs.fat -F 32 /dev/sdb1This command formats the partition
/dev/sdb1 as a FAT32 filesystem. mkfs.fat will usually default to FAT32 for larger partitions.2. Format with a volume label:
sudo mkfs.fat -F 32 -n MY_USB_DRIVE /dev/sdb1This command formats
/dev/sdb1 as FAT32 and assigns the volume label MY_USB_DRIVE.3. Create FAT16 filesystem with custom cluster size:
sudo mkfs.fat -F 16 -s 16 /dev/sdc2This formats
/dev/sdc2 as FAT16, setting the cluster size to 16 sectors (8KB if sector size is 512 bytes). This can be useful for specific applications or older devices that expect a particular cluster size.4. Format and check for bad blocks:
sudo mkfs.fat -c /dev/sdd1This command formats
/dev/sdd1 with the default FAT type and performs a scan for bad blocks during the process. This can significantly increase the formatting time but helps ensure data integrity.
FAT FILESYSTEM TYPES
The FAT filesystem family includes three main variants, each with different capabilities and limitations:
FAT12: The oldest version, primarily used for very small disks (e.g., floppy disks) due to its limited partition size (up to 32MB) and file size.
FAT16: An evolution of FAT12, commonly used for larger partitions (up to 2GB or 4GB depending on sector size and cluster size). It has a 2GB/4GB maximum individual file size limit.
FAT32: The most common FAT variant today, supporting much larger partitions (up to 2TB) and still maintaining wide compatibility. However, it retains the 4GB maximum individual file size limit, which can be a constraint for modern media like large video files.
HISTORY
The mkfs.fat command is part of the dosfstools package, which provides a set of utilities for creating, checking, and maintaining FAT filesystems on Linux. Historically, its functionality was often provided by symlinks such as mkfs.msdos or mkfs.vfat, which pointed to the same underlying executable. The name mkfs.fat is now widely adopted as the canonical command, reflecting its capability to create all variants of the FAT filesystem (FAT12, FAT16, and FAT32). Its development has been driven by the need for robust and compatible tools to interact with storage devices that commonly use FAT, particularly for interoperability with Microsoft Windows systems and embedded devices. The command maintains a long-standing presence in Linux distributions, evolving with improvements in FAT specifications and hardware capabilities.


