I’ve been working with disk images from the excellent crew from Hypriot and there are times when I wish to mount the filesystems within to inspect and or make alterations to them. Since there are multiple filesystems, it’s not like mounting an ISO image — there’s more work which needs to be done.
Being a “lazy”(pronounced SMART) sysadmin type, I did some research and discovered a wonderful tool called kpartx — it will read the partition table of the image and create device mappings for the partitions.
Typically it is called as follows:
1 2 3 4 5 |
$ sudo kpartx -av IMAGE_FILE add map loop2p1 (252:4): 0 131072 linear /dev/loop2 2048 add map loop2p2 (252:5): 0 2296567 linear /dev/loop2 133120 $ mount /dev/mapper/loop2p1 /mnt |
Note: despite the line saying /dev/loop2
, the partition’s synthetic device is actually at /dev/mapper/loop2p1