Learn through the super-clean Baeldung Pro experience:
>> Membership and Baeldung Pro.
No ads, dark-mode and 6 months free of IntelliJ Idea Ultimate to start with.
Last updated: April 27, 2025
FAT32 is a relatively old file system, yet it’s still widely used, from USB sticks and SD cards to portable hard disks. Its main strengths are its simplicity and cross-platform compatibility. However, its simplicity makes it more prone to failure. An unexpected power outage or removing a drive without properly ejecting it can lead to corruption.
On Linux, fixing a corrupted FAT32 drive isn’t quite the same as repairing ext4 or NTFS file systems. Thus, tools like fsck won’t work the way we expect. Instead, we turn to dosfsck, a utility made specifically for FAT file systems.
In this tutorial, we’ll see how to safely check, understand, and repair a corrupted FAT32 volume using tools that work well with Linux.
FAT32 stands for File Allocation Table, and it was created by Microsoft way back in 1996. It is light, basic, and highly supported, so it’s ideal for removable media. However, its lack of journaling, i.e., not keeping a real-time log of changes before applying them to the disk, makes it susceptible to unstable conditions.
Corruption in removable media most commonly occurs when a storage device is ejected while still in the process of writing. We also see this due to improper shutdowns, faulty sectors, or even logical inconsistencies due to old hardware. In the real world, symptoms manifest themselves in the form of the drive not mounting, appearing as read-only, or displaying file system errors.
Since FAT32 isn’t a native Linux file system, the usual tool we’d use to repair filesystems, e.g., fsck, doesn’t quite work here. Instead, we need something that understands how FAT works under the hood. That’s where dosfsck (or its alias fsck.vfat) utility comes into play. These are purpose-built tools for checking and repairing FAT32 drives, and they come bundled with the dosfstools package, which is often already installed on many Linux systems.
Before jumping into repairs, we should always play it safe so that we don’t lose any important data. The first step is to create a full backup or clone of the corrupted drive using dd. That way, if anything goes wrong during the repair, our data isn’t lost for good.
Let’s see how to quickly create a backup image of the corrupted drive using dd. First, we need to identify the drive using lsblk or fdisk -l. Once we know the device name (like /dev/sdc1), we can create a backup image. Usually, the pendrive is mounted at /dev/sdc1, but the actual device name may vary across systems.
Let’s create a backup image of the corrupted drive:
$ sudo dd if=/dev/sdc1 of=~/backup_corrupted.img bs=4M status=progress
Here, if specifies the input file (the corrupted drive), and of specifies the output file (the backup image). The bs=4M option sets the block size to 4 Megabytes for faster copying, and status=progress shows us the progress of the operation. This command will create a backup image of the corrupted drive in our home directory. We can adjust the of path to save it elsewhere if needed.
Next, we must unmount the partition before running any repair tool:
$ sudo umount /dev/sdc1
Unmounting ensures that no process interferes during repair. Attempting a repair on a mounted volume could worsen the corruption.
dosfsck is a utility tailored for FAT file systems. It checks for logical errors, dirty bits, and inconsistencies in directory structures or cluster chains.
We can use apt to install it on Debian-based systems:
$ sudo apt install dosfstools
Once installed, we can run a basic check:
$ sudo dosfsck -v /dev/sdc1
Alternatively, we can use its alias:
$ sudo fsck.vfat -v /dev/sdc1
In both of these commands, the -v flag stands for verbose mode, which provides detailed output about the file system’s state. This is useful for diagnosing issues before attempting repairs.
Let’s see another useful command using dosfsck for automatic repairs:
$ sudo dosfsck -a /dev/sdc1
This command runs in auto-repair mode with minimal prompts. The -a flag means automatic repair.
The output usually lists details such as the dirty bit status, invalid clusters, cross-linked files, or orphaned directory entries. The tool attempts to repair these issues or moves affected files to a FOUND.000 directory.
After a successful run, there’s a high chance that we’ll find our drive mountable again. If issues still persist, we might be dealing with a dirty bit.
A dirty bit is a flag in the metadata that tells the operating system that the volume wasn’t cleanly unmounted. FAT32 marks this bit during each write and clears it upon safe removal. If this bit remains set, Linux might refuse to mount the drive.
Usually, we can clear it by repairing the file system with dosfsck:
$ sudo dosfsck -a /dev/sdc1
However, sometimes Linux tools can’t fix this issue fully. In that case, we need to resort to Windows utilities, since FAT32 is primarily a Windows format. We can then plug the drive into a Windows machine and use chkdsk to resolve the issue.
If this still doesn’t work, we can try mounting the drive as read-only to access the data using the mount utility:
$ sudo mount -o ro /dev/sdc1 /mnt/usb
This enables us to copy data safely before deeper repairs or reformatting.
If dosfsck doesn’t fix the issue, or the file system is beyond logical repair, recovery tools come into play.
We start with testdisk, a powerful open-source tool that can reconstruct partition tables and recover deleted files.
We can run the following commands to install testdisk:
$ sudo apt install testdisk
Let’s run testdisk to analyze the disk:
$ sudo testdisk /dev/sdc1
We can then follow the terminal UI to select the disk, analyze partitions, and recover files.
If nothing works, our last option is to reformat the drive:
$ sudo mkfs.vfat -F 32 /dev/sdc1
Of course, we should only do this after backing up everything possible.
We can avoid most FAT32 issues by following a few habits. First, we should always unmount drives before unplugging:
$ sudo umount /dev/sdc1
We can also mount with the sync option to force write-through behavior:
$ sudo mount -o sync /dev/sdc1 /mnt/usb
This reduces the chance of write-cache issues. Moreover, for Linux-only drives, we should use the ext4 format with journaling, which is much safer.
Lastly, we can monitor disk health using smartctl from the smartmontools package:
$ sudo apt install smartmontools
$ sudo smartctl -a /dev/sdc1
Here, the -a option with smartctl shows all available information about the drive. This includes temperature, read/write errors, and overall health status. Regular checks can help us catch issues before they escalate.
In this article, we explored how to use dosfsck, also known as fsck.vfat, and recovery tools like testdisk to repair FAT32 file systems. We’ve also learned how to recognize and address dirty bit issues. With this knowledge, we can now recover, repair, or, if necessary, reformat a corrupted FAT32 partition, all from our Linux terminal.