Thursday, September 5, 2013

Accessing a LVM partion inside a Guest OS Raw Image

Sometimes its handy to be able to access the contents of a Guest OS image before/without booting it up.

It can be a pain as the kernel doesn't recognize the devices without a few extra commands.

For quick refence here they are:

To mount an LVM partition:

  • kpartx -a /var/lib/libvirt/images/CentOSGuest.img
  • pvscan
  • vgchange -ay vg_centguest
  • mount /dev/mapper/vg_centguest-lv_root /mnt
Note: The pvscan is optional, it's useful to allow you to check the group name.

Then to un-mount:
  • umount /mnt
  • vgchange -an vg_centguest
  • kpartx -d /var/lib/libvirt/images/CentGuesst.img

Behind the scenes, this will create a loop device /dev/loop0 so you may want to increase the number of available devices by editing /etc/modules.conf and add the following line:

options loop max_loop=64