I have a slightly messed-up 64GB USB drive formatted with FAT32, and would like to fix it on Ubuntu 18.04.
First attempt:
$ sudo fsck.vfat /dev/sdc1
fsck.fat 4.1 (2017-01-24)
FATs differ but appear to be intact. Use which FAT ?
1) Use first FAT
2) Use second FAT
? 1
Reclaimed 4221 unused clusters (138313728 bytes).
Free cluster summary wrong (1484695 vs. really 1488915)
1) Correct
2) Don't correct
? 1
Perform changes ? (y/n) y
/dev/sdc1: 20 files, 402763/1891678 clusters
$
However, when I re-mount the drive afterwards, the corrupt files show up again and resist any attempt to delete them. I can re-run the command as often as I want, with exactly the same result.
Second attempt, based on How to repair a corrupted FAT32 file system:
$ sudo fsck.vfat -w -r -v -l -a -t /dev/sdc1
fsck.fat 4.1 (2017-01-24)
Checking we can access the last sector of the filesystem
Boot sector contents:
System ID "THREES "
Media byte 0xf8 (hard disk)
512 bytes per logical sector
32768 bytes per cluster
32 reserved sectors
First FAT starts at byte 16384 (sector 32)
2 FATs, 32 bit entries
7567872 bytes per FAT (= 14781 sectors)
Root directory start at cluster 2 (arbitrary size)
Data area starts at byte 15152128 (sector 29594)
1891678 data clusters (61986504704 bytes)
63 sectors/track, 32 heads
63 hidden sectors
121097025 sectors total
FATs differ but appear to be intact. Using first FAT.
Checking file /
[...]
Checking for bad clusters.
Reclaiming unconnected clusters.
Reclaimed 4221 unused clusters (138313728 bytes) in 1 chain.
Checking free cluster summary.
Free cluster summary wrong (1484695 vs. really 1484694)
Auto-correcting.
Performing changes.
/dev/sdc1: 21 files, 406984/1891678 clusters
Same result: fsck finds errors, acts like it fixes them, but the filesystem appears to be entirely unchanged afterwards and all the corrupt files are still there.
Filesystem has been unmounted before fsck, of course. What am I missing?
It is possible that the drive is 'gridlocked', which means that it seems to be OK, but is actually read-only (the hardware is read-only). This is sometimes the first stage of failure.
But if you are lucky, there is another error, and you can get rid of the problem.
There are more details at this link.