kpartx is a tool which creates device maps from partition tables. Assume that you have a .img disk image which contains various partitions and you want to mount one or more of the partitions. kpartx will map each partition to a loop device under /dev/mapper and will allow you to mount the loop device to a local directory and access the files.
Mapping an image:
# kpartx -a /foo/bar/disk.img
Checking which loop device was used to mount the partitions:
# kpartx -l /foo/bar/disk.img loop1p1 : 0 8177022 /dev/loop1 63
The disk image has one partition and is mapped to /dev/loop1p1. You can now mount the partition:
# mount /dev/mapper/loop1p1 /mnt/img
Once finished, you can remove the mapper device:
# kpartx -d /foo/bar/disk.img loop deleted : /dev/loop1
3 thoughts on “Mounting partitions within image file”
Pingback: mount qemu image
Pingback: Firmware: Debian v0.3 for Flytouch SD bootable.
If you have problems removing
device-mapper: remove ioctl failed: Device or resource busy
unmount the tmp_dir like this >
sudo umount “/foo/bar/tmp_dir”
Then remove like described above.