Howto mount a guest LVM disk on host
Note: guest is called bup in the example
Setup¶
-
Snapshot the guests running LVM volume (guests virtual disk)
$ sudo lvcreate --size 100m --snapshot --name snap-bup /dev/vg_raid1/bup Logical volume "snap-bup" created
-
Setup a loop device for the virtual disk snapshot
$ sudo losetup -f /dev/vg_raid1/snap-bup /dev/loop0: [0005]:49084 (/dev/mapper/vg_raid1-snap--bup)
-
Create device maps from the loop back device
$ sudo kpartx -av /dev/loop0 add map loop0p1 (251:16): 0 3817472 linear /dev/loop0 2048 add map loop0p2 (251:17): 0 272386 linear /dev/loop0 3821566 add map loop0p5 (251:18): 0 272384 251:17 2
-
mount
Now you can mount a partition the the snapshot of the guest disk, example mounting partition one.
$ sudo mount /dev/mapper/loop0p1 /mnt/ -o ro
Clean-up¶
-
Un-mount all mounted partitions
$ sudo umount /mnt ...
-
Delete partition mappings
$ sudo kpartx -dv /dev/loop0 del devmap : loop0p5 del devmap : loop0p2 del devmap : loop0p1
-
Detach loop device
$ sudo losetup -d /dev/loop0
-
Remove LVM snapshot
$ sudo lvremove /dev/vg_raid1/snap-bup Do you really want to remove active logical volume snap-bup? [y/n]: y Logical volume "snap-bup" successfully removed