Mount A Single Partition Inside A Disk Image

I've recently had to mount a single partition which was inside of an IMG (dd-style disk image) file. If you want to mount one of the partitions inside of that, just follow these two simple steps.

First: Determine partition offset - where does your partition start?

# fdisk -lc /path/to/disk.img
Disk disk.img: 7,2 GiB, 7746879488 bytes, 15130624 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
Disklabel type: dos
Disk identifier: 0xe505dfac

Device                    Boot  Start     End Sectors  Size Id Type
disk.img1                 *      2048  526336  524289  256M  c W95 FAT32 (LBA)
disk.img2                      528384 7958527 7430144  3,6G 83 Linux

You might notice that this image contains two partitions. I'd like to mount the second one and have to calculate its offset with 528384 * 512 (see unit size in fdisk output). My partition starts at byte 270532608.

Second: Mount the partition from image file by specifying its offset

# mount /path/to/disk.img /mountpoint -o offset=270532608

Done!

0 Comments Mar 29, 2016 share to diaspora*