Difference between revisions of "Access a LVM-based DomU disk outside of the domU"

From Xen
m (Formatting)
m
Line 50: Line 50:
   
 
[[Category:Xen]]
 
[[Category:Xen]]
[[Category:User]]
+
[[Category:Users]]
[[Category:Beginner]]
+
[[Category:Beginners]]
 
[[Category:HowTo]]
 
[[Category:HowTo]]

Revision as of 18:43, 9 November 2011


If you've installed a domU using virt-install (ie. Fedora/CentOS/RHEL), which by default uses LVM, or otherwise used LVM inside the domU, trying to access the disk in your dom0 is difficult. After using kpartx to reveal the partition structure of the disk image, trying to mount just gives you a file system error. If you need to access the disk (to fix file system corruption, as an example), this is really annoying. Fortunately, there's a method.

In this example, my domU is installed on a logical volume called 'helium'.

Step 1

kpartx -a /path/to/logical/volume

For me, this was kpartx -a /dev/domU/helium. This created two block devices in /dev/mapper - domU-helium1 and domU-helium2. helium1 was my /boot, helium2 was the partition used by LVM to store the root and swap space.

Step 2

vgscan

This will give you a list of the volume groups on your system, hopefully including the volume group from your domU.

Step 3

vgchange -a y volume_group_from_VM

This will activate the logical volumes in the VG. Block devices should appear in /dev/mapper. For me, what appeared was vg_helium-lv_root and vg_helium-lv_swap.

Step 4

Do whatever you want with the disk image. For the purposes of this walkthrough, run a disk check with

fsck /dev/mapper/vg_helium-lv_root

Replace vg_helium-lv_root with your volume group and logical volume name. Wait for the check to finish before starting to clean up after yourself.

Step 5

vgchange -a n volume_group_from_VM

This will deactivate the volume group so LVM won't complain when you destroy the block devices that represent the domU LVM.

Step 6

kpartx -d /path/to/logical/volume
 

To clean up, you have to destroy the block devices that kpartx created so Xen doesn't complain that the logical volume already being accessed.