System and processes

The mkfs.vfat command

Formats a partition or USB device with FAT (FAT12, FAT16 or FAT32) so Windows, macOS and Linux can read it without installing anything. It erases everything that was there before.

Syntax

mkfs.vfat [opciones] dispositivoTry it in the terminal →

Most useful options

-F 12|16|32FAT type. For current drives use 32, although FAT32 limits each file to 4 GB
-n ETIQUETAVolume name, up to 11 characters. It is the name shown in the file manager
-cChecks for bad sectors before formatting. It takes longer, but it warns about failures

Copy-ready examples

$ lsblkidentifies the device before anything else. Check the size and the name, for example sdb1.

Example output

NAME   SIZE TYPE
sda    477G disk
└─sda1 477G part
sdb     14G disk
└─sdb1  14G part
$ sudo mkfs.vfat -F 32 -n DATOS /dev/sdb1formats sdb1 as FAT32 with the label DATOS. Everything before is gone.

Example output

mkfs.fat 4.2 (2021-01-31)

You can try them in the browser terminal: it does not touch your computer.

Common errors

MessageCauseFix
No error messageYou gave the system disk or one you do not want to erase. Formatting erases everything without asking for confirmation.Check the exact name and size with lsblk before running it again.
mkfs.fat: /dev/sdb1 contains a mounted filesystem.The partition is mounted and the system is using it.Unmount it with sudo umount /dev/sdb1 and run the command again.
mkfs.fat: unable to open /dev/sdb1: Permission deniedYou do not have permission to write to the device.Put sudo in front of the command.

Typical mistakes

  • FAT does not store Unix permissions or owners, so chmod and chown have no effect on these volumes.
  • FAT32 does not support files larger than 4 GB. If you will store large videos, use exFAT.
  • Formatting creates a new table and does not securely erase the content. To remove old signatures, use wipefs.

Differences from similar commands

  • mkfs.ext4: creates a Linux filesystem. Windows cannot read it without extra software, so for a shared USB drive use FAT or exFAT.
  • mkfs.exfat: has no 4 GB per-file limit like FAT32 and Windows and macOS can read it. It may not work on very old machines.
  • fdisk: creates and edits partitions, but does not format them. Partition with fdisk first, then format with mkfs.vfat.

Security

mkfs.vfat asks for no confirmation and keeps no backup. A wrong device name, such as sdb instead of sdc, can erase the disk that boots the machine. Always check the size with lsblk before formatting.

FAQ

FAT32 or exFAT for a USB drive?

To share with Windows and macOS without the 4 GB limit, exFAT. For old or unsupported devices, FAT32.

How do I know which filesystem a USB drive has?

With lsblk -f, which shows the type in the FSTYPE column, or with blkid on the partition.

More System and processes commands

Learn to actually use it

The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.

Start the free course