Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




Fedora Core 6 Xen Virtualization Guide
Previous Page Home Next Page

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 -t ext3 -diskimage /xen/images/fc5-file.img -partition 1 /mnt/boot

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

  • # yum install device-mapper-multipath
    # kpartx -av /dev/xen/guest1
    add map guest1p1 : 0 208782 linear /dev/xen/guest1 63
    add map guest1p2 : 0 16563015 linear /dev/xen/guest1 208845

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:

  • # losetup -f
    # losetup /dev/loop0 /xen/images/fc5-file.img
    # kpartx -av /dev/loop0
    add map loop0p1 : 0 208782 linear /dev/loop0 63
    add map loop0p2 : 0 12370050 linear /dev/loop0 208845

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.

Fedora Core 6 Xen Virtualization Guide
Previous Page Home Next Page

  Published under the terms of the GNU General Public License Design by Interspire