Mounting a partition from a dd image

At some point, everybody may have done a dd image of a USB/SD stick, as the below example shows:

dd if=/dev/sdb of=foo.img 

But it is usual that at some point in time we would like to access the information inside the image, doing that is quite easy:

First,you should do a fdisk on the image:

fdisk -l foo.img

Disk foo.img: 7998 MB, 7998537728 bytes, 15622144 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002fc6d

Device Boot      Start         End      Blocks   Id  System
foo.img1   *             15622143     7811071+   c  W95 FAT32 (LBA)

Then some maths are needed. The operators are the start of the partition and the sector size in bytes.  The operation is simply start * sector size in bytes.

In this particular case the operation is 1 * 512 = 512.

Now that we have the result, that we call the offset. In other words, 512 is the offset where the partition starts in this dd image.

So the command to mount the partition is:

mount -t vfat -o loop,ro,noexec,offset=512 foo.img /mnt/mountpoint

And then we can copy the information from the partition inside!

 

 

 

 

No Comments yet »

RSS feed for comments on this post. TrackBack URI

Leave a comment

XHTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.