I've got a USB pen drive with a corrupted FAT filesystem. Now I try to repair it. So to first try what I can get from it without endangering the original hardware further, I've created an image with dd using the following command line:

$ sudo dd if=/dev/sdb of=pendrive.img

Now I want to repair the filesystem in the image by running fsck.

But fsck immediately terminates as follows:

$ sudo fsck.vfat -a -t -v pendrive.img
fsck.fat 3.0.27 (2014-11-12)
Logical sector size is zero.

Is there any trick how I can tell fsck to assume a sector size or what does this message mean? Can somebody help interpreting this output?

This question is similar to fsck a filesystem in a file but this was about ext2. Also https://superuser.com/questions/129189/cant-mount-fat32-drive-under-ubuntu-linux gave no answer.

  • What was the exact command line you used to make the image? – Tero Kilkanen Oct 14 '16 at 14:40
  • @TeroKilkanen I've added the info the the question – white_gecko Oct 14 '16 at 14:52

You have made the image of your whole USB pen drive with your dd command. This means that the image includes also a partition table.

That is why you cannot mount the image directly as a file system.

To mount the filesystem inside the image, you need to use kpartx utility to generate virtual devices from the partition table in your image.

kpartx -v -a /path/to/image

will create new partition mappings inside your /dev/mapper directory, which will point to the actual partitions inside your image. Then you can use these entries as the device for mount command or for fsck.vfat command.

  • 8-| sure I was aware of this, wen I selected the dev file, but not now, that I started fsck :-D thx – white_gecko Oct 14 '16 at 15:14
  • Funny, I can mojnt the filesystem using sudo mount -o loop /path/to.img /mnt and read the files without a problem. – reinierpost Jun 15 '17 at 20:13
  • This works when the device doesn't have a partition table and all the device space is used for the filesystem itself. – Tero Kilkanen Jun 16 '17 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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