Home / Alt manpages / fsck.fat(8)

  • fsck.fat(8)
  • Admin command
  • linux

Safely Check and Repair a FAT Filesystem with fsck.fat

You will finish with a cautious workflow for checking a FAT12, FAT16 or FAT32 filesystem, deciding whether repair is safe, and confirming the result. The examples match fsck.fat 4.2 from the locally installed dosfstools package. Allow 15 minutes for a healthy volume, plus whatever time you need to identify the correct device and protect its data.

You need a shell and a FAT filesystem that is not mounted. Repairing a real block device normally needs elevated privileges. The command names dosfsck, fsck.msdos and fsck.vfat are aliases for the same program on this installation; use fsck.fat in new notes and scripts.

1. Identify the volume before touching it

Do not guess a device path. A mistaken path can check the wrong disk, and a repair command can alter it. List block devices and their filesystem types, then record the exact FAT device, such as /dev/sdb1:

$ lsblk -o NAME,SIZE,FSTYPE,LABEL,MOUNTPOINTS
$ command -v fsck.fat
/usr/sbin/fsck.fat
$ dpkg-query -W -f='${Package} ${Version}\n' dosfstools
dosfstools 4.2-1

Replace /dev/sdb1 below only after checking the listing. If the filesystem is mounted, stop and unmount it using your normal maintenance procedure. Never run a repair against a live filesystem: concurrent writes can make the checker see a moving target and can corrupt data.

Checkpoint

You have the intended device, its type is FAT, and no process is using it through a mount point.

2. Run a read-only assessment

Use -n first. It checks non-interactively and does not write to the filesystem, so this is the ordinary, low-risk inspection step:

$ fsck.fat -n /dev/sdb1
fsck.fat 4.2 (2021-01-31)
/dev/sdb1: 12 files, 184/4081 clusters

The final line is volume-specific. A clean check exits with status 0. Status 1 means recoverable errors were found, or that fsck.fat found an internal inconsistency. Status 2 means a usage error and that the filesystem was not accessed. Capture the status directly when scripting:

$ fsck.fat -n /dev/sdb1
$ check_status=$?
$ printf 'fsck.fat status: %s\n' "$check_status"
fsck.fat status: 0

Do not treat a non-zero result as permission to retry with automatic repair. First read the diagnostic, confirm the device, and make a backup or image if the data matters.

3. Get more detail without changing data

Add -v when you need the boot-sector layout, FAT size or cluster counts. This remains a read-only check when combined with -n:

$ fsck.fat -n -v /dev/sdb1
fsck.fat 4.2 (2021-01-31)
Checking we can access the last sector of the filesystem
Boot sector contents:
       512 bytes per logical sector
         2 FATs, 12 bit entries
/dev/sdb1: 12 files, 184/4081 clusters

Your output will contain values from the volume, not these sample numbers. The default DOS codepage for decoding short names is 850. If filenames are displayed incorrectly, specify the codepage documented for that volume with -c PAGE; do not change it just to make a warning disappear.

For a second pass after a repair, -V repeats the check. It can take considerably longer, because the first pass may have caused many modifications to be scanned again.

4. Decide what repair means before enabling it

Automatic repair is -a, also available as -p or -y. The normal automatic mode chooses the least destructive method when there is more than one option. It can still truncate files, remove bad directory entries, discard shared or invalid clusters, change volume labels, and free clusters that are marked used but owned by no file.

That is a data-changing operation. Stop here if you cannot accept those outcomes. Preserve an image or backup first, and make sure the device remains unmounted. Do not use -w casually: without it, fsck.fat accumulates changes in memory and writes them after all checks complete; -w writes changes immediately, reducing the opportunity to stop safely.

Warning

-f changes the recovery choice. It salvages unused cluster chains into files named fsck0000.rec, fsck0001.rec and so on in the filesystem's top-level directory. In automatic mode, unused clusters are otherwise added to free space. Plan where those recovered files will go before using this option.

5. Repair, then repeat the check

When you have confirmed the device and accepted the possible file changes, run automatic repair and request a verification pass. This needs elevated privileges for a protected block device:

$ sudo fsck.fat -a -V /dev/sdb1
fsck.fat 4.2 (2021-01-31)
/dev/sdb1: 12 files, 184/4081 clusters

The exact questions and repair messages depend on the damage. With -a, no interactive advice is requested. Keep the complete output and the exit status. A successful second pass should not report fixable errors, but status 0 is still the useful final signal:

$ printf 'repair status: %s\n' "$?"
repair status: 0

If the command reports errors or stops, do not repeatedly rerun it with increasingly forceful options. Preserve the output, take an image if possible, and work from a copy. An invalid boot-sector parameter is detected but is not repaired by fsck.fat.

6. Keep specialised options in reserve

-t tests for unreadable clusters, marks them bad and removes them from files that own them. Use it only when you have considered the consequences of losing data in affected clusters. -F NUM selects a particular FAT table and is mainly for a damaged first cluster; a non-zero table number is required for that repair. Treat both as recovery work, not routine health checks.

-d PATH deletes a named file, while -u PATH attempts to undelete one by allocating a contiguous chain of unallocated clusters. Neither is a general backup or undelete system. The default interactive mode is -r, but it is retained mainly for compatibility; use it only when you are present to review each choice.

There is no undo command for repairs. If you need to reverse a changed volume, restore the verified backup or image you made before step 5. Only after the second check succeeds should you remount the volume and inspect important files.

Done means

  • The exact FAT device was identified and was unmounted before checking.
  • fsck.fat -n completed first, with its exit status recorded.
  • Any automatic repair was an intentional, backed-up, elevated operation.
  • The repaired filesystem passed the requested verification pass.
  • Special options such as -f, -t, -F, -d and -u were used only for a stated recovery purpose.