Repair FAT filesystem on image

5,358

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.

Share:
5,358

Related videos on Youtube

white_gecko
Author by

white_gecko

I'm working with PHP for many years now but also looked into Android development with Java. Currently I'm mainly interested in web development and web engineering related topics especially Semantic Web.

Updated on September 18, 2022

Comments

  • white_gecko
    white_gecko over 1 year

    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.

    • Tero Kilkanen
      Tero Kilkanen over 7 years
      What was the exact command line you used to make the image?
    • white_gecko
      white_gecko over 7 years
      @TeroKilkanen I've added the info the the question
  • white_gecko
    white_gecko over 7 years
    8-| sure I was aware of this, wen I selected the dev file, but not now, that I started fsck :-D thx
  • Tero Kilkanen
    Tero Kilkanen almost 7 years
    This works when the device doesn't have a partition table and all the device space is used for the filesystem itself.