Mount a partition of image file

Solution 1: losetup

With newer version of losetup, you can easy map parition in image file to /dev/loop*.

$ sudo losetup --show -Pf <imagefile>
/dev/loop0

The output will show which loop device has been mapped to image file. Now you can mount partition of it.
Example:

$ sudo mount /dev/loop0p1 /mnt

To detach, run sudo losetup --detach /dev/loop0.

Solution 2: qemu-nbd

Load module nbd

$ sudo modprobe nbd max_part=16

Connect /dev/nbd0 with image file

$ sudo qemu-nbd -c /dev/nbd0 <imagefile>

Update partition table

$ sudo partprobe /dev/nbd0

Mount partition of image

$ sudo mount /dev/nbd0p1 /mnt

To detach, run sudo qemu-nbd -d /dev/nbd0.

qemu 

See also

comments powered by Disqus