FAT
The File Allocation Table (FAT) - filesystem originally created for use with MS-DOS (and later pre-NT Microsoft Windows). Currently a later revision of FAT (FAT32) is used for USB flash disks.[1] It has made its way over to Linux systems and has official support in the Linux kernel.
Although FAT32 lacks many of the features inherent in modern file systems, this filesystem can still be found in modern computers, for example, when using EFI System Partition. In 2006 Microsoft has developed a new version of FAT (exFAT) that is not backward compatible with the previous version. See the exFAT article for more info.
Installation
Kernel
File systems --->
DOS/FAT/NT Filesystems --->
< > MSDOS fs support
<*> VFAT (Windows-95) fs support
(437) Default codepage for FAT
(iso8859-1) Default iocharset for FAT
[ ] Enable FAT UTF-8 option by default
-*- Native language support --->
(iso8859-1) Default NLS Option
<*> Codepage 437 (United States, Canada)
<*> NLS ISO 8859-1 (Latin 1; Western European Languages)
-*- NLS UTF-8
When planning on mounting FAT partitions, users may need to specify a codepage=
option with mount. In the example above the codepage for the United States and Canada is used, however other codepages can be enabled a necessary. Optionally, users can also set a default codepage for FAT in the kernel configuration. Be sure each codepage value which is to be used has been enabled in the kernel.
Using the
codepage
option via the mount will override the settings used in the kernel.Avoid setting Default iocharset for fat
to UTF-8; it is not recommended. Instead, pass the utf8=true
option when mounting FAT partitions (this requires CONFIG_NLS_UTF8 to be enabled in the kernel). For further information see mount(8) man page or see the appropriate kernel documentation at /usr/src/linux/Documentation/filesystems/vfat.rst
Emerge
The sys-fs/dosfstools package is needed for FAT userspace utilities:
root #
emerge --ask sys-fs/dosfstools
Usage
To create an FAT file system, use mkfs.fat:
user $
mkfs.fat
mkfs.fat 4.2 (2021-01-31) No device specified. Usage: mkfs.fat [OPTIONS] TARGET [BLOCKS] Create FAT filesystem in TARGET, which can be a block device or file. Use only up to BLOCKS 1024 byte blocks if specified. With the -C option, file TARGET will be created with a size of 1024 bytes times BLOCKS, which must be specified. Options: -a Disable alignment of data structures -A Toggle Atari variant of the filesystem -b SECTOR Select SECTOR as location of the FAT32 backup boot sector -c Check device for bad blocks before creating the filesystem -C Create file TARGET then create filesystem in it -D NUMBER Write BIOS drive number NUMBER to boot sector -f COUNT Create COUNT file allocation tables -F SIZE Select FAT size SIZE (12, 16 or 32) -g GEOM Select disk geometry: heads/sectors_per_track -h NUMBER Write hidden sectors NUMBER to boot sector -i VOLID Set volume ID to VOLID (a 32 bit hexadecimal number) -I Ignore and disable safety checks -l FILENAME Read bad blocks list from FILENAME -m FILENAME Replace default error message in boot block with contents of FILENAME -M TYPE Set media type in boot sector to TYPE --mbr[=y|n|a] Fill (fake) MBR table with one partition which spans whole disk -n LABEL Set volume name to LABEL (up to 11 characters long) --codepage=N use DOS codepage N to encode label (default: 850) -r COUNT Make room for at least COUNT entries in the root directory -R COUNT Set minimal number of reserved sectors to COUNT -s COUNT Set number of sectors per cluster to COUNT -S SIZE Select a sector size of SIZE (a power of two, at least 512) -v Verbose execution --variant=TYPE Select variant TYPE of filesystem (standard or Atari) --invariant Use constants for randomly generated or time based values --offset=SECTOR Write the filesystem at a specific sector into the device file. --help Show this help message and exit
Formatting
To format /dev/sdx9 partition with FAT32 filesystem with label "ESP" with verbose output.
root #
mkfs.fat -v -F 32 -n "ESP" /dev/sdx9
It should be possible to mount FAT filesystems with the mount command. Resizing could be done using sys-fs/fatresize.
Troubleshooting
Slow file transfer speeds
If file transfer speeds are slow (can be viewed using iotop), ensure the filesystem is mounted with the async
filesystem option. Edit /etc/fstab (or /etc/autofs/auto.misc when using autofs) system files as needed, likely removing the sync
mount option. By default, filesystems are mounted using the async
mount option.
The filesystem
sync
mount option inhibits slower transfer speeds than the default async
mount option.
The sync
mount option may cause flash media life-cycle shortening also! See man mount option sync
explanation.If file transfer speeds are still slow, try remounting the filesystem with the flush
mount option:
root #
mount -o remount,flush /path/to/mountpoint
Alternative operating system compatible filesystems
Try UDF filesystem using UDFTools, requiring sys-fs/udftools and Linux kernel UDF filesystem driver. Recently code was added to mkudffs for a fix for creating a mock partition increasing compatibility with Microsoft related operating systems. If using an older Linux kernel, ensure block size is set to 512 for increased compatibility. Most options are now default for compatibility, except for the required --bootarea=mbr
creating the mock partition.
root #
mkudffs --bootarea=mbr --label=your_label /dev/device_file
Try Samsung's F2FS filesystem.
UTF-8/UTF-16 character hardware bugs
Sometimes hardware firmware bugs will occur on embedded devices (eg. car radios) when reading their required formatted FAT/FAT32 filesystems containing UTF-8 characters. A workaround is to ensure initially mounting the FAT filesystem using (current default) mount options codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro
.
For short filenames, codepage=437
is IBM-PC characters or basically ASCII. For long filenames, iocharset=iso8859-1
specifies ASCII. The option shortname=mixed
is default, and can also try shortname=win95
option. Of which, are all current defaults. Additionally to further remedy UTF-8/UTF-16 incompatible characters, use a loop with sed to replace all incompatible UTF-8/UTF-16 characters with an underscore or other ASCII character. (See this replace_chars.sh script.)
For reference, this bug was encountered with a Sony car radio. The MEX-GS610BT radio model would hard reset upon attempting to read a USB flash media/drive containing UTF-8/UTF-16 characters.
As mentioned previously, see /usr/src/linux/Documentation/filesystems/vfat.txt, the Linux Kernel vfat source code documentation, for further explanation on whether to use codepage, iocharset, or utf8 mount options.
Unsorted files and folders
When writing files to the FAT/FAT32 filesystem, devices used for reading the filesystem may show the files and folders as unsorted. Commonly, viewer prefer seeing files and folders sorted alphabetically. Install sys-fs/fatsort, and issue the following command:
root #
fatsort /dev/device_file
See also
- ExFAT — a Microsoft file system optimized for flash memory storage
- ext4 — an open source disk filesystem and most recent version of the extended series of filesystems.
- btrfs — a copy-on-write (CoW) filesystem for Linux aimed at implementing advanced features while focusing on fault tolerance, self-healing properties, and easy administration.
- removable media — any media that is easily removed from a system.
- /etc/fstab — a configuration file that defines how and where the main filesystems are to be mounted, especially at boot time.
External resources
- /usr/src/linux/Documentation/filesystems/vfat.txt - Documentation on the VFAT filesystem included with the Linux kernel sources.
- FAT filesystem and Linux - from Wikipedia