Accessing data on a guest disk image
There are two tools which can help greatly in accessing data within a guest disk image: lomount and kpartx. Remember never to do this while the guest is up and running, as you could corrupt the filesystem if you try to access it from the guest and dom0 at the same time!
* lomount
lomount only works with small disk images and cannot deal with LVM volumes, so for more complex cases, kpartx (from the device-mapper-multipath RPM) is preferred:
* kpartx
Note that this only works for block devices, not for images installed on regular files. To use file images, you'll need to set up a loopback device for the file first:
In this case we have added an image formatted as a default Fedora install, so it has two partitions: one /boot, and one LVM volume containing everything else. They are accessible under /dev/mapper:
-
# ls -l /dev/mapper/ | grep guest1
brw-rw---- 1 root disk 253, 6 Jun 6 10:32 xen-guest1
brw-rw---- 1 root disk 253, 14 Jun 6 11:13 guest1p1
brw-rw---- 1 root disk 253, 15 Jun 6 11:13 guest1p2
# mount /dev/mapper/guest1p1 /mnt/boot/
To access LVM volumes on the second partition, we'll need to rescan LVM with "vgscan" and activate the volume group on that partition (named "VolGroup00" by default) with "vgchange -ay":
-
# kpartx -a /dev/xen/guest1
# vgscan
Reading all physical volumes. This may take a while...
Found volume group "VolGroup00" using metadata type lvm2
# vgchange -ay VolGroup00
2 logical volume(s) in volume group "VolGroup00" now active
# lvs
LV VG Attr LSize Origin Snap% Move Log Copy%
LogVol00 VolGroup00 -wi-a- 5.06G
LogVol01 VolGroup00 -wi-a- 800.00M
# mount /dev/VolGroup00/LogVol00 /mnt/
...
# umount /mnt
# vgchange -an VolGroup00
# kpartx -d /dev/xen/guest1
Note: always remember to deactivate the logical volumes with "vgchange -an", remove the partitions with "kpartx -d", and (if appropriate) delete the loop device with "losetup -d" after you are finished. There are two reasons: first of all, the default volume group name for a FC install is always the same, so if you end up activating two disk images at the same time you'll end up with two separate LVM volume groups with the same name. LVM will cope as best it can, but you won't be able to distinguish between these two groups on the command line.
And secondly, if you don't deactivate it, then if the guest is started up again, you might end up with the LVM being active in both the guest and the dom0 at the same time, and this may lead to VG or filesystem corruption.