Ref: https://www.linuxquestions.org/questions/linux-general-1/how-to-mount-img-file-882386/#post4365399
To list the partitions of a disk image:
$ fdisk -l mydisk.img
Disk mydisk.img: 15 GiB, 16088301568 bytes, 31422464 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: 0xce5f7383
Device Boot Start End Sectors Size Id Type
mydisk.img1 8192 97921 89730 43.8M c W95 FAT32 (LBA)
mydisk.img2 98304 31422463 31324160 15G 83 Linux
To mount a partition from a disk image:
-
You must first figure out the block size in your image file. In the above example is
512
bytes:Units: sectors of 1 * 512 = 512 bytes
-
Then find the starting block (Start) of the partition of interest. In the above example, the first partition starts at
8192
and the second at98304
:Device Boot Start End Sectors Size Id Type mydisk.img1 8192 97921 89730 43.8M c W95 FAT32 (LBA) mydisk.img2 98304 31422463 31324160 15G 83 Linux
-
Finally, multiply the start block by the block size to obtain the offset and use the following
mount
command:$ mount -o loop,offset=<OFFSET> mydisk.img /mnt $ mount -o loop,offset=4194304 mydisk.img /mnt # in the example, the 1st partition (8192 * 512) $ mount -o loop,offset=50331648 mydisk.img /mnt # in the example, the 2nd partition (98304 * 512)