Mount a partition of a full disk image

The Raspberry Pi images are whole disk images, and they contain generally two partitions inside. To mount one of those partitions you can use this method.

First, inspect the image file to see the start sector of the partition we want to mount:

# fdisk -l ./Fedora-Server-armhfp-22-1-sda.raw
Disk ./Fedora-Server-armhfp-22-1-sda.raw: 4 GiB, 4219469824 bytes, 8241152 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: 0xeca43266

Device                               Boot   Start     End Sectors   Size Id Type
./Fedora-Server-armhfp-22-1-sda.raw1         2048 1001471  999424   488M 83 Linux
./Fedora-Server-armhfp-22-1-sda.raw2      1001472 2001953 1000482 488,5M 83 Linux
./Fedora-Server-armhfp-22-1-sda.raw3      2001954 7861328 5859375   2,8G 83 Linux

To mount the third partition, we must get the partition offset multiplying the sector size (512 bytes) by the start sector (2001954).

512 x 2001954 = 1025000448

Then, we create the loop device with the obtained offset and mount it:

# losetup -o 1025000448 /dev/loop0 ./Fedora-Server-armhfp-22-1-sda.raw
# mount /dev/loop0 /mnt/img
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s