Recently one of my VMs crashed, and couldn't reboot due to filesystem
corruption. It's a Fedora 13 host, and I installed a Fedora 13 VM
using virt-install, which by default creates an LVM for the root
partition. Now, the partition that was corrupted was the root
partition, so I couldn't boot into the VM and recover it, like I would
if /home was corrupted.
Because I searched to mostly no avail how to recover a partition in a
logical volume in a VM which itself is in a logical volume on the VM
host, which the LV partitioned into /boot and the remaining space used
for LVM, I'm posting the steps here, hopefully so someone in a similar
situation can be helped.
Step 1: Run 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 used for LVM.
Step 2: Run vgscan.
This will give you a list of the volume groups on your system,
hopefully including the volume group from your domU.
Step 3: Run 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.
>From there, it's a simple fsck /dev/mapper/vg_helium-lv_root. Wait for
it to finish before you clean up after yourself.
Step 4: To clean up, you have to deactivate the LVs before destroying
the block devices that kpartx created. To do this, run vgchange -a n
Step 5: Finally, run kpartx -d /path/to/logical/volume
Hopefully this helps someone - Googling "Recover file system xen
image" and variants thereof mainly turned up references to kpartx, not
the necessary LVM stuff. The most helpful link was
http://support.citrix.com/article/CTX117791, but it seems overly
complicated and has XenServer specific tools mentioned.
I'll see if I can update the xen wiki too...
Xen-users mailing list