109

I'm using the FAT32 file system for my pen drive. It frequently has file/data corruptions.

In Windows, I used the scan disk utility to fix the FAT32/NTFS file systems. How can I do this in Ubuntu?

  • 3
    Do you safely eject? – ζ-- Jun 6 '12 at 12:20
125

Try typing the following command in the Linux terminal:

sudo dosfsck -w -r -l -a -v -t /dev/sdc1

sdc1 is usually your pen drive. You can find your pen drive by typing mount in terminal. It's somewhere inside. If that command takes too much time for you, avoid -t switch.

  • -w means write to disk immediately.
  • -r means to do disk check interactively (ask you what to do to when encountering errors). On newer versions of dosfsck this is the default.
  • -l means to list the filenames processed.
  • -a means automatically fix errors. Do not use it, if You want to have more control over fixing possible errors.
  • -v means verbose mode. Generates slightly more output.
  • -t means mark unreadable clusters as bad.

If you want to be sure not to lose your data, create a backup of the source device first.

  • What other file system this command capable to fix other than FAT32? – Shaharil Ahmad Nov 28 '13 at 8:53
  • @ShaharilAhmad FAT16, which maybe still be used. For example I got an mini 2GB sd card with FAT16. – keiki Jul 5 '14 at 9:36
  • But if I don't do -t, then next time it tries again to use the bad clusters next time? – keiki Jul 5 '14 at 9:37
  • "Currently, only 1 or 2 FATs are supported, not 0." – Aaron Franke Oct 4 '18 at 15:11
  • don't use -a, but I don't understand how to answer half the questions it asks me! – Michael Feb 7 at 4:26
51
+100

You can try Dosfsck, which is a component of dosfstools.

For this, type in terminal:

sudo apt-get install dosfstools

To use Dosfsck, you have to indicate the device address you want (Ex. /dev/sdb1, /dev/sdb2, or other device.).

To know your device address, open the terminal (CTRL+ALT+T), then run this command:

mount

If your partition is /dev/sdb1, for example, then unmount it first by running this command:

sudo umount /dev/sdb1

Now you can verify and repair your partition by running this command:

sudo dosfsck -t -a -w /dev/sdb1

Hope this helps.

Note:

if you receive the following error, when your USB flash drive is not recognized:

Error: Buffer I/O error on device sdb1

Run this command:

dmesg|tail

If the output is:

end_request: I/O error, dev sdb1, sector 0
Buffer I/O error on device sdb1, logical block 0

Run this command:

sudo dosfsck -t -a /dev/sdb1

Of course, you must change the device address to your needs, like i wrote above.

  • in 13.04 the umount seems to work also without sudo – giuspen Jun 7 '13 at 8:13
  • I've always encountered with the problem that if an external HDD or pen drive was disconnected improperly whilst making operations with it, the permissions would go crazy, making the device virtually useless. Your answer feels like a god-sent to me; thanks a lot man! – Alfredo Hernández Jul 22 '16 at 15:37
6

Also try:

fsck.vfat -r /dev/sdXn
4

dosfsck cheatsheet

These examples will use FAT32 and /dev/sdc1

fsck.vfat -n /dev/sdc1 - a simple non-interactive read-only check

fsck.vfat -a /dev/sdc1 - checks the file system and fixes non-interactively. Least destructive approach is always used.

fsck.vfat -r /dev/sdc1 - interactive repair. User is always prompted when there is more than a single approach to fixing a problem.

fsck.vfat -l -v -a -t /dev/sdc1 - a very verbose way of checking and repairing the filesystem non-interactively. The -t parameter will mark unreadable clusters as bad, thus making them unavailable to newly created files and directories.

protected by souravc Aug 16 at 15:01

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.