Linux: How to mount a partition that is inside a disk image file dump.

The Problem:

I have a disk image file (created by dd).  It is an image of an entire drive and contains partitions.  I would like to be able to mount one of those partitions inside Linux.  Can this be done?

Like lots of things in Unix based OS, the answer is a resounding ‘YES! If you try hard enough!’.  I’m sick of trying hard so I’m posting the answer here in case it happens to help someone else.

The Solution:

First we need to find out the sector layout of our partition system inside the image filfdisk -l /path/to/image

In my case this gives me something like:

 

Now we can mount is as a loop device with a simple calculation of the byte offset of the partition.  In my case I want to mount the first partition and I now know it starts at sector 2048

I also know the sector size is 512 bytes so I can work out the offset ( 512 x 2048 = 1048576 ) i.e. its exactly 1MB offset inside the file.

Lets mount it.

Thats it :)…

Enjoy.