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

From Xen
(Migrated page)
 
m (Formatting)
Line 10: Line 10:
 
In this example, my domU is installed on a logical volume called 'helium'.
 
In this example, my domU is installed on a logical volume called 'helium'.
   
Step 1: Run
+
= Step 1 =
 
 
 
<pre><nowiki>
 
<pre><nowiki>
 
kpartx -a /path/to/logical/volume</nowiki></pre>
 
kpartx -a /path/to/logical/volume</nowiki></pre>
Line 18: Line 16:
 
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.
 
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: Run
+
= Step 2 =
 
 
 
<pre><nowiki>
 
<pre><nowiki>
 
vgscan</nowiki></pre>
 
vgscan</nowiki></pre>
Line 26: Line 22:
 
This will give you a list of the volume groups on your system, hopefully including the volume group from your domU.
 
This will give you a list of the volume groups on your system, hopefully including the volume group from your domU.
   
Step 3: Run
+
= Step 3 =
 
 
 
<pre><nowiki>
 
<pre><nowiki>
 
vgchange -a y volume_group_from_VM</nowiki></pre>
 
vgchange -a y volume_group_from_VM</nowiki></pre>
Line 34: Line 28:
 
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.
 
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 =
Step 4: Do whatever you want with the disk image. For the purposes of this walkthrough, run a disk check with
 
  +
Do whatever you want with the disk image. For the purposes of this walkthrough, run a disk check with
 
   
 
<pre><nowiki>
 
<pre><nowiki>
Line 42: Line 36:
 
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.
 
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: Run
+
= Step 5 =
 
 
 
<pre><nowiki>
 
<pre><nowiki>
 
vgchange -a n volume_group_from_VM</nowiki></pre>
 
vgchange -a n volume_group_from_VM</nowiki></pre>
Line 50: Line 42:
 
This will deactivate the volume group so LVM won't complain when you destroy the block devices that represent the domU LVM.
 
This will deactivate the volume group so LVM won't complain when you destroy the block devices that represent the domU LVM.
   
Step 6: Finally, run
+
= Step 6 =
 
 
 
<pre><nowiki>
 
<pre><nowiki>
 
kpartx -d /path/to/logical/volume
 
kpartx -d /path/to/logical/volume

Revision as of 17:12, 8 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.