Mounting filesystem of VM from dom0 in XEN

virtualizationxenxenserver

I have XEN 4.0.x.x and Cent os 5.5

There is an .image file of each VM stored on dom0 in /var/lib/xen/images directory. Is it a some block on the hard disk which I can mount this file from dom0 and access the file system of dom0.

What I really want to do is mount the filesystem of VM, and access /etc/sysconfig/network-scripts directory. Is there a way I can o it.

I tried directly using 'mount -o loop /var/lib/xen/images/VMname.img ', but it failed asking for the filesystem type. I didn't get any file system type using 'file' command for this image. Is this image an accessible file or some kind of binary or system file that XEN creates. If it is a binary file, I think we can't do much with it. But if it is in accessible format, we can do something with it. I want to know the way with which I can do eactly that.

Best Answer

The virtual machine image is more like a full harddrive than a single file system that you can mount, which mean it has a partition table. You can use the kpartx tool to make all of the partitions available to be mounted like so:

# kpartx -av /var/lib/xen/images/VMname.img
add map loop0p1 : 0 29333504 linear /dev/loop0 2048
add map loop0p5 : 0 1380352 linear /dev/loop0 29337600
# mount /dev/mapper/loop0p1 /mnt

When you're done and have unmounted all the partitions, you can remove them from the device mapper with this:

# kpartx -d /var/lib/xen/images/VMname.img

(Note, example cribbed from http://ppadala.net/blog/2010/09/kpartx-to-mount-vm-disk-images/)

For more extensive modification, you may wish to take a look at the guestfish tool.

Related Topic