MKFS.FAT(8)

๐ŸŽ€ MKFS.FAT(8) ๐ŸŽ€

System Manager's Manual, the official Unix manual for this one ๐Ÿ’…

โœจ NAME โœจ

mkfs.fat - create an MS-DOS FAT filesystem ๐Ÿ’–

โœจ SYNOPSIS โœจ

mkfs.fat [OPTIONS] DEVICE [BLOCK-COUNT]

โœจ DESCRIPTION โœจ

okay so mkfs.fat is how you make a FAT filesystem ๐Ÿงš on a device, or inside an image file. DEVICE is the special file for the device (like /dev/sdXX) or the image file. The image file doesn't have to exist yet if you pass -C ๐Ÿฆ‹

BLOCK-COUNT is the number of blocks on the device, and a block is always 1024 bytes, no matter the sector size or cluster size ๐Ÿคฏ So BLOCK-COUNT is the size of the filesystem in KiB, NOT in sectors (unlike every other mkfs.fat option, bestie ๐Ÿ™ˆ). If you leave it out, mkfs.fat picks a size that fills all the available space. โœจ

There are two flavours of FAT filesystem ๐ŸŒˆ Standard is FAT12, FAT16 and FAT32, the ones Microsoft defined and that everyone uses on hard disks and removable stuff like USB sticks and SD cards ๐Ÿ’œ The other one is the legacy Atari variant, used on Atari ST machines ๐Ÿ‘พ

In Atari mode, unless you tell it otherwise, mkfs.fat always uses 2 sectors per cluster, because GEMDOS does NOT like other values ๐Ÿ’€ It also obeys the max number of sectors GEMDOS can handle. Bigger filesystems get handled by raising the logical sector size. It generates an Atari-compatible serial number for the filesystem, and only uses a 12 bit FAT for the usual floppy sizes (720k, 1.2M, 1.44M, 2.88M). Everything else gets a 16 bit FAT. You can override that with -F. Some PC-specific boot sector fields don't get written, and a boot message (-m) gets ignored ๐Ÿฅบ

โœจ OPTIONS โœจ

  • -a โ€” By default, for any filesystem that isn't tiny, mkfs.fat aligns all the data structures to the cluster size, so that as long as the partition is aligned, everything in the filesystem is too ๐Ÿซถ This flag turns alignment OFF. You get a handful of extra clusters back, but you pay with a big performance hit on RAIDs, flash media, or large-sector hard disks ๐Ÿ˜ญ
  • -A โ€” Flips between the Atari variant and the standard FAT filesystem. If Atari is already on, it selects standard, and vice versa. It's picked by default when you run mkfs.fat on 68k Atari Linux ๐Ÿ‘‘
  • -b SECTOR-OF-BACKUP โ€” Picks where the backup boot sector for FAT32 lives. It depends on the number of reserved sectors, but it's usually sector 6 ๐Ÿ“ If there's free space after the backup boot sector, the backup of the FAT32 info sector goes right after it, usually at sector 7. The backup has to fall inside the reserved sectors range. A value of 0 totally disables making the backup boot and info FAT32 sectors.
  • -c โ€” Checks the device for bad blocks before it makes the filesystem ๐Ÿ”
  • -C โ€” Creates the file you gave as DEVICE and writes the new filesystem into it. This is perfect if you want a filesystem in a file instead of on a real device, and it saves you from using dd beforehand to make a file of the right size ๐Ÿฐ With this flag, BLOCK-COUNT is required, because otherwise there's no way to know how big you want it. The file is sparse, which means it only really stores the metadata areas (boot sector, FATs, and root directory). The data parts aren't stored on disk, but the file still ends up the correct size ๐Ÿง  You can copy it onto a floppy or another device later, or mount it through a loop device.
  • -D DRIVE-NUMBER โ€” Sets the BIOS drive number that gets stored in the FAT boot sector. For hard disks and removable media it's usually 0x80โ€“0xFF (0x80 is the first hard disk C:, 0x81 is the second hard disk D:, and so on). For floppy devices, or partitions used for floppy emulation, it's 0x00โ€“0x7F (0x00 is the first floppy A:, 0x01 is the second floppy B:) ๐Ÿ’พ
  • -f NUMBER-OF-FATS โ€” Sets how many file allocation tables the filesystem has. The default is 2 โœจ
  • -F FAT-SIZE โ€” Sets the type of file allocation table (12, 16 or 32 bit). If you don't specify it, mkfs.fat automatically picks whichever of 12, 16 and 32 bit fits the filesystem size best ๐Ÿง
  • -g HEADS/SECTORS-PER-TRACK โ€” Gives the HEADS and SECTORS-PER-TRACK numbers that describe the disk geometry of DEVICE. Both get stored in the FAT boot sector. SECTORS-PER-TRACK is also used to align the total count of FAT sectors ๐Ÿ“ By default the geometry is read from DEVICE itself. If that's not available, it falls back to LBA-Assist Translation plus a translation table from the SD Card Part 2 File System Specification, based on the total number of disk sectors.
  • -h NUMBER-OF-HIDDEN-SECTORS โ€” Sets the number of so-called hidden sectors, stored in the FAT boot sector. This number is the starting sector of the partition holding the filesystem ๐Ÿซฃ Usually it's an offset (in sectors) from the start of the disk. But for MBR logical volumes inside an extended partition of type 0x05 (a non-LBA extended partition), a quirk in MS-DOS's FAT means it has to be relative to that partition's immediate containing Extended Boot Record. Boot code and other software that handles FAT volumes may also rely on this field being correct, though most modern FAT implementations ignore it. By default, if DEVICE is a partition block device, mkfs.fat uses the partition offset relative to the disk start. Otherwise it assumes zero. Use this option to override that ๐Ÿ™…โ€โ™€๏ธ
  • -i VOLUME-ID โ€” Sets the volume ID of the new filesystem. VOLUME-ID is a 32-bit hexadecimal number (for example, 2e24ec82) ๐Ÿ”ข The default is a number based on the filesystem creation time.
  • -I โ€” Ignores and disables the safety checks. By default mkfs.fat refuses to make a filesystem on a device that has partitions or virtual mappings, and it'll complain and tell you it won't work ๐Ÿšซ This is different for MO disks, since you don't always need partitions on those. The filesystem can go straight onto the whole disk, which other OSes call the "superfloppy" format. This switch forces mkfs.fat to work anyway ๐Ÿ’ช
  • -l FILENAME โ€” Reads the bad blocks list from FILENAME ๐Ÿ“
  • -m MESSAGE-FILE โ€” Sets the message you get when you try to boot this filesystem without a properly installed operating system ๐Ÿ™ƒ The message file can't be bigger than 418 bytes once line feeds are converted to carriage return-line feed pairs and tabs are expanded. If the filename is a hyphen (-), the text is read from standard input.
  • -M FAT-MEDIA-TYPE โ€” Sets the media type stored in the FAT boot sector. It's usually 0xF8 for hard disks, and 0xF0 or a value from 0xF9 to 0xFF for floppies or partitions used for floppy emulation ๐Ÿฅฏ
  • --mbr[=y|yes|n|no|a|auto] โ€” Fills in a (fake) MBR table with a disk signature and one partition that starts at sector 0 (including the MBR itself) and spans the whole disk device. This is only needed for non-removable disks used on Microsoft Windows systems, and only when you're formatting a whole unpartitioned disk ๐ŸชŸ The disk signature and partition table overlap with the end of the first FAT sector (where the boot code lives), so it doesn't use any extra space. The default is auto mode, which only puts an MBR table on non-removable disks when formatting a whole unpartitioned disk โœจ
  • -n VOLUME-NAME โ€” Sets the volume name (label) of the filesystem. It can be up to 11 characters long ๐Ÿท๏ธ An empty string, a string made only of whitespace, or the string "NO NAME" as VOLUME-NAME does the same thing as not using -n at all. The default is no label.
  • --codepage=PAGE โ€” Uses DOS codepage PAGE to encode the label. By default codepage 850 is used ๐ŸŒ
  • -r ROOT-DIR-ENTRIES โ€” Picks the minimum number of entries in the root directory. The default is 112 or 224 for floppies and 512 for hard disks. This is the MINIMUM, so mkfs.fat might bump it up because of structure alignment. See also -a ๐Ÿ“‚
  • -R NUMBER-OF-RESERVED-SECTORS โ€” Picks the minimum number of reserved sectors. With the FAT32 format you need at least 2 reserved sectors, and the default is 32. Otherwise the default is 1 (just the boot sector). Like -r, this is a minimum, so mkfs.fat may increase it for alignment. See also -a ๐Ÿงธ
  • -s SECTORS-PER-CLUSTER โ€” Sets the number of disk sectors per cluster. It has to be a power of 2, so 1, 2, 4, 8, ... up to 128 ๐Ÿ”ข
  • -S LOGICAL-SECTOR-SIZE โ€” Sets the number of bytes per logical sector. It has to be a power of 2 and at least 512: 512, 1024, 2048, 4096, 8192, 16384, or 32768. Heads up: values bigger than 4096 don't conform to the FAT filesystem spec and might not work everywhere ๐Ÿšจ
  • -v โ€” Verbose mode, so you get all the details as it goes ๐Ÿ“ฃ
  • --offset SECTOR โ€” Writes the filesystem starting at a specific sector inside the device file. This is handy for making a filesystem in a partitioned disk image WITHOUT needing to set up a loop device ๐Ÿงšโ€โ™€๏ธ
  • --variant TYPE โ€” Creates a filesystem of variant TYPE. The acceptable values are standard and atari (any upper/lower case combo works). Check DESCRIPTION above for the differences ๐Ÿ’…
  • --help โ€” Shows the option summary and exits ๐Ÿ†˜
  • --invariant โ€” Uses constants in place of the stuff that's normally random or time based, like the volume ID and creation time. Running mkfs.fat multiple times on the same device gives identical results with this flag. Its main purpose is testing mkfs.fat itself ๐Ÿงช

โœจ BUGS โœจ

โš ๏ธ mkfs.fat can NOT create boot-able filesystems. It's not as easy as it sounds at first, for various reasons, and it's been discussed a LOT already. mkfs.fat simply will not support it ;)

โœจ SEE ALSO โœจ

fatlabel(8), fsck.fat(8) ๐Ÿซถ

โœจ HOMEPAGE โœจ

The home for the dosfstools project is its GitHub project page ๐ŸŒธ

โœจ AUTHORS โœจ

dosfstools were written by Werner Almesberger, Roman Hodek, and others ๐Ÿ‘‘ Current maintainers are Andreas Bombe and Pali Rohรกr ๐Ÿซถ


dosfstools 4.2, dated 2021-01-31, that's your sign-off bestie, you're officially a FAT filesystem expert now ๐Ÿ’–๐Ÿฆ‹โœจ

๐Ÿ“ฆ where this page comes from