Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
don't you mean you tried 'mount -o loop /var/lib/xen/images/<vm>.image <target>' ? Because you can't really mount a whole directory of images – blauwblaatje Sep 22 '11 at 11:37
Yes I tried this command, but I can't get what you are exactly asking? – stillStudent Sep 22 '11 at 11:41
Well, you say in the post that you use 'mount -o loop /var/lib/xen/images/' that implies that you try to mount the whole directory and not just on 1 image file. – blauwblaatje Sep 22 '11 at 12:43
No No, sorry for wrong representation, but i tried to only one single image file and whole directory. – stillStudent Sep 22 '11 at 12:52
up vote 2 down vote accepted

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

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

share|improve this answer
Hi, you guys are really great, it half worked for me. But there is one more problem I am facing. I am able to mount the first mapping without specifying file system. This mapping is 'boot' partition of the system. But when I try to mount second mapping, it throws error asking for filesystem type. 'file' command shows it as block. Not sure which file system to provide. But at least it has helped me to try further. Any further assistance will be of great help, as I am still not able to access /etc/sysconfig directory of VM. – stillStudent Sep 23 '11 at 7:46
It's possible the root partition of the domU is in an LVM partition. vgscan should pick that up if that is the case. You may also want to take a look at guestfish: – Ophidian Sep 23 '11 at 12:54

As you can see from the above comments I was not able to mount second loop as it was again a LVM partition. I finally found a way to mount a VM.img file and do any configuration on guest machine from Dom-0.

Please follow the below steps to mount the image file:

  1. First fire vgscan command on dom-0, it will give you logical volumes that are currently active on the dom-0. Now you can safely assume that this volume number shown by the command is of your dom-0 machine and not of any guest.

  2. Now execute kpartx -av /var/lib/xen/images/$machine_name.img This command will map loops for the image file of VM and activate the VolumeGroup of guest VM.

  3. Now again fire vgscan command, you will see one more VolGroup other than what you have seen in step 1. Now you can be sure that this is the volumegroup of your guest VM.

  4. Now you should know the logical volumes in a VolumeGroup to successfully mount it. For this fire the command vgchange -ay /VolGroup00(Newly created volumegroup in step 2)/

  5. Now execute command lvs, this will give you logical volumes in VolGroup.

  6. Now create a mount point and mount any Logical volume you want to mount as follows

    mount /dev/VolGroup00/LogVol00 $mount_path

  7. Now you can access any directory of Guest VM through this way and modify any configuration you want. Once you are done you can follow reverse procedure like

    a) Umount $mount_path

    b) vgchange -an VolGroup00

    c) kpartx -d /var/lib/xen/images/$machine_name.img

And you are done

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.