Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there anyway to browse a .img file without mounting it? I have an .img file which I have generated from a clonezilla partition snapshot. I somehow have problems mounting the file with the command mount -o loop sda5.img /mnt/.

dmesg | tail shows me the following error:

[ 1325.395286] EXT4-fs (loop0): bad geometry: block count 11221248 exceeds size of device (11218432 blocks)

Anyone got an idea how to browse without mounting or what might be causing this error?

share|improve this question
    
That looks bad. –  Uri Herrera Jan 4 '13 at 19:43

2 Answers 2

If this is an image of a whole hard drive or as in your case this might be an image of an extended partition, you will need to know the partition layout and the offsets of each partition in the file to be able to mount them.

To do this you will need the parted tool, you can install it with the following command:

apt-get install parted

After installing parted, start it with the path to your image file. A parted prompt will be shown:

$ parted /path/to/image/file/sda5.img
GNU Parted 2.3
.....
(parted)

In this prompt (prefixed with (parted)) type the following commands:

(parted) unit B
(parted) print
.....
Number  Start          End            Size           Type     File system  Flags
 1      1048576B       1573912575B    1572864000B    primary  ntfs         boot
 2      1573912576B    156774694911B  155200782336B  primary  ntfs
 3      156774694912B  171454758911B  14680064000B   primary  ntfs
 4      171454758912B  180044693503B  8589934592B    primary

(parted) q

The table in the output will tell you the offsets of each partition in the file and the filesystem type in each partition. For example to mount the first partition in the exemplary output above you will need to enter following command:

sudo mount -o loop,ro,offset=1048576 /path/to/image/file/sda5.img /mnt/partition

Make sure that /mnt/partition exists first.

share|improve this answer
1  
Ok, I think the problem might be that I get an error, when running the print command, because it says unknown partiton table. Guess the image is broken? –  Ahatius Jan 5 '13 at 6:59
    
Looks very much like it's broken. But try to serch for your error on Google first. –  bender Jan 5 '13 at 14:31

I got this same issue with an ext4 image generated from a Clonezilla snapshot.

What actually worked for me was to extend the file to the size the partition table reports, using truncate. The error dmesg reported in my case was:

[15687.653868] EXT4-fs (loop0): bad geometry: block count 18482176 exceeds size
  of device (18352672 blocks)

So I adjusted the length of the file with:

truncate -o -s 18482176 /path/to/partition.img

(^ note that's the first, and larger of the two numbers in the log)

After that mount was happy and I could access my data.

share|improve this answer
    
This worked for me although the size was wrong, I guess the block sizes were different, so I had to specify the size in bytes. Be careful because you can lose data if you truncate your image file to a size shorter than the original size. –  golimar May 8 '13 at 13:10
    
How you know the correct size? please add the commands here. –  user230137 Jul 19 at 16:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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