Mount disk image partition

In case NDB (https://gist.github.com/shamil/62935d9b456a6f9877b5) is not available, eg CentOS7, you can try this.

From https://www.linuxquestions.org/questions/linux-general-1/how-to-mount-img-file-882386/, first get partition starting sector:

[labuser@tip-dev-1 ~]$ sudo fdisk -l disk-ia.img

Disk disk-ia.img: 113.6 GB, 113561141760 bytes, 221799105 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 label type: dos
Disk identifier: 0x419f5b94

      Device Boot      Start         End      Blocks   Id  System
disk-ia.img1   *        2048     1050623      524288    b  W95 FAT32
disk-ia.img2         1052670   209713151   104330241    5  Extended
disk-ia.img5         1052672   209713151   104330240   83  Linux

If we are interested on disk-ia.img5 partition, then use 1052672 x 512 = 538968064 so we can mount the partition using:

sudo mount -o loop,offset=538968064 disk-ia.img /mnt/

Finally, when you are done, just umount /mnt. If you want, you can check (losetup –list) that umount command destroys the loop device created, just in case you have any doubt.

Leave a comment