On Fedora's Xen wiki, there's a tutorial on how to read a xen guest OS's disk from the outside. The instruction works for a physical LVM, but when the disk is actually an image file, the instruction there does not really work. Here I share my experience, step by step, in the hope of saving somebody else's time.
The problem that the original instruction doesn't work is because many people (including myself) simply use Fedora's default Volume Group name, VolGroup00 in both dom0 and guest systems. Therefore, vgscan will be confused by two volume groups with the same name and gathers only the info of the one currently working, i.e. the one used in dom0. Since LVM basically provides a unique name for volume accessing, there is no way that we can assign a particular logical volume within a particular volume group, without having a unique name for it.
The solution is to change the name of one of them. Since we usually deal with many guest systems on the same dom0, I choose to change the name for dom0. (It's also possible to change the guest system instead by steps similar to the below, but note that it can only be done from the inside.)
Use Rescue Mode to access the system's root file system
- Reboot into the rescue mode (insert FC5 DVD, CD1, or Rescue CD, and at the boot prompt, type linux rescue).
- Choose language and keyboard layout.
- Choose No when asked about bringing up the network.
- When prompted about mounting the original file system, press F2 to bring up a shell.
- Wait for a while (for the background lvm process to find necessary info).
Change the volume group's name
- At the # prompt, type lvm vgrename VolGroup00 VGHost00
Change original references to the volume group's name
- # cd /mnt
- # mkdir root boot
- # mount /dev/mapper/VGHost00-LogVol00 /mnt/root
- # vi root/etc/fstab (replace VolGroup00 with VGHost00, you can use :%s/VolGroup00/VGHost00/g to do so and use ZZ to quit vi)
- # umount root; rm -rf root
- # mount /dev/hda1 /mnt/boot
- # vi boot/grub/grub.config (do the same substitution)
- # umount boot; rm -rf boot
Now we need to build a new init ramdisk that knows about the new volume group (reference from this blog)
- Press F1 to go back to the rescue menu where it asks about mounting the original system,select Continue (you can also manually mount it -- see the blog reference above)
- # chroot /mnt/sysimage
- # cp /boot/initrd-2.6.16-1.2133_FC5xen0.img /boot/initrd-2.6.16-1.2133_FC5xen0.old.img
- # mkinitrd -v -f /boot/initrd-2.6.16-1.2133_FC5xen0.img 2.6.16-1.2133_FC5xen0
- # exit
- # exit
- Remember to remove the Fedora DVD/CD1/RescueCD to boot from your HD
Read the disk image of the guest OS
- Use losetup -f to find a free loopback device. Here we assume it's /dev/loop0
- # losetup /dev/loop0 your_disk_image_file
- # kpartx -av /dev/loop0 (this should give us loop0p1 loop0p2 under /dev/mapper)
- # vgscan (this should report both VolGroup00 and VGHost00)
- # vgchange -ay VolGroup00
- # mkdir /mnt/guest_root
- # mount /dev/mapper/VolGroup00-LogVol00 /mnt/guest_root
To unmount it, basically we just reverse the steps:
- umount /mnt/guest_root
- rm -rf /mnt/guest_root
- vgchange -an VolGroup00
- kpartx -d /dev/loop0
- losetup -d /dev/loop0