How can I mount a disk image?
The kpartx tool makes this easier. It creates loop devices in /dev/mapper for each partition in your image. Then you can mount the loop device that corresponds with your desired partition without having to calculate the offset manually.
For example, to mount the first partition of the disk image:
kpartx -a -v myimage.disk
mount /dev/mapper/loop0p1 /mnt/myimage
When you're done with the image, remove the loop devices:
umount /mnt/myimage
kpartx -d -v myimage.disk
Alternatively, if you have a recent kernel, and pass loop.max_part=63 on boot (if loop is built-in) or to modprobe (if loop is a module), then you can do it this way:
losetup /dev/loop0 myimage.disk
partprobe /dev/loop0 # Re-read partition table if /dev/loop0 was used with a different image before
mount /dev/loop0p1 /mnt/myimage
When you're done with the loop:
losetup -d /dev/loop0
Found this:
http://www.andremiller.net/content/mounting-hard-disk-image-including-partitions-using-linux
which seems exactly what I was looking for.
Here's the key part:
mount -o loop,ro,offset=32256 hda.img /mnt/rabbit
where the value of offset is in bytes. The suggested way to get the offset is to point parted
at the image, then unit B for bytes and take the start value from the print output. As an alternative, assuming you have the disk space, do the obvious: once you have the offset and size, just use dd
to extract each partition to a separate file.
Nowadays you can minimize your work by using udisks
. Solution from ArchWiki: udisks - Mount loop devices
To easily mount ISO images, use the following command:
udisksctl loop-setup -r -f image.iso
This will create a loop device and show the ISO image ready to mount. Once unmounted, the loop device will be terminated by udev.
-r
there for read only option.