mount_a_single_partition_from_a_dd_disk_image

mount a single partition from a dd disk image

if you have an image file created from a single partition using dd, you can simply use

mount -o loop yourimage.img /mountpoint

to mount it. however, things get a bit more complicated if the image at hand was made of a complete disk containing several partitions.

now you can either use a partitioning tool like fdisk to figure tout the partition boundaries of the partition you want to mount and then use losetup to create a loop device for that partition which you can then mount, or you can use a handy tool called kpartx which will do it all for you with a single command.. isn't that nice :) the tool can be found in most distributions repo, so simply install it with your packet manager. in ubutu the package is called kpartx

to have kpartx create a loop device and mappings in /dev/mapper/ for all your imaged partitions simply run (as root or using sudo)

kpartx -av yourimage.img

and it will tell you which loop devices it has created:

add map loop0p1 (252:0): 0 129024 linear /dev/loop0 8192
add map loop0p2 (252:1): 0 2578432 linear /dev/loop0 137216

now simply mount your partition as you would mount any partition on a regular block device and you're done

mount /dev/mapper/loop0p2 /mnt/

when you're done, you can unmount the partition and then remove the mappings:

umount /mnt
kpartx -d yourimage.img

in case your os automounted some other partitions after the mappings where created you might see an error message like this:

ioctl: LOOP_CLR_FD: No such device or address

simply unmount that now defunct partition and the mapping will disappear

You can also remove the mapping by loop device:

kpartx -d /dev/loop1

in case you have lost track of which image was mounted to which loop device, you can use losetup to list the mappings:

losetup -a 

or on newer versions of losetup:

losetup --list
  • mount_a_single_partition_from_a_dd_disk_image.txt
  • Last modified: 26.04.2017 10:03
  • by Pascal Suter