Mount a disk image containing LVM

Hard_DiskIf you have an image with standard partitions, you can mount any partition as a loopback device using the offset given by fdisk:

The sda5 partition starts on sector 204804096. We know from fdisk -l that one sector is made of 512 bytes, so we need to multiply that number: 204804096 * 512 = 104859697152

Now we can mount the partition using the specified offset (in bytes):

LVM

However, if there is LVM inside that image, the above described procedure won’t work. In this case, we need to use the whole image as a loop device first:

losetup is used to set up and control the loop device on /dev/loop0, while kpartx maps the partitions of the image and maps them as virtual block devices in /dev/mapper.

We’ll now be able to see the partitions in /dev/mapper/ as /dev/mapper/loop0p1 and /dev/mapper/loop0p2. Now, we can work with volume groups as usual

Tagged with: ,