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 it could corrupt the filesystem:
* 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, 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, 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 performing the above steps. The default volume group name for a Fedora install is always the same, it is important to avoid activating two volume group of the same name at the same time. LVM will cope as best it can, but it is not possible to distinguish between these two groups on the command line. In addition, if the volume group is active on the host and the guest at the same time, it can cause filesystem corruption.