How to Duplicate Xen DomU Virtual Machines

Assumption: There are VBD based Xen DomU virtual machines stored under /lhome/xen/vm-f11-sample/. There are two files under vm-f11-sample: (The configuration file) and vmdisk0 (The virtual disk). Now we want to duplicate the virtual machine vm0 stored under vm-f11-sample to vm- which is stored under vm- And vm-’s ip will be The steps to duplicate this virtual machine:

1) Duplicate the virtual disk and configuration files

# cp -rv vm-f11-sample vm-

For security reason, the owner of the virtual machine’s files is root. So we need to copy these files as root. The destination directory is vm- And here we should make sure that vm0 is powered off. If vm0 is power on before this step, we need to shut it down first.

2) Change the file names and the configuration file

# cd vm-
# mv
# vim

This is the content of

disk = ['file:/lhome/xen/vm-,xvda,w' ]
vif = [ 'bridge=eth0' ]
bootloader = "/usr/bin/pygrub"
on_reboot = 'restart'
on_crash = 'restart'

The name and disk entry are changed.

3) Start the new virtual machine and configure the new virtual machine

# xm create /lhome/xen/vm-
# xm console

After logging in vm-, we can edit the network configuration file:

#  vi /etc/sysconfig/network-scripts/ifcfg-eth0

Change the IPADDR to Then restart eth0:

# ifdown eth0
# ifup eth0

Make sure this interface doesn’t have

HWADDR by commenting out the line that specify HWADDR if we use Xen bridge network. Log out of vm- and then use “Ctrl + ]” to exit the xm console. Reset vm- on Dom0:

# xm reset

The new virtual machine vm- is running now.

Eric is a father and systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

2 Replies to “How to Duplicate Xen DomU Virtual Machines”

  1. Hi Eric,

    I think to configure a new virtual machine we do not need to start it just mount it and use chroot to the mount point.

    mount /lhome/xen/vm- /mnt/tmp
    chroot /mnt/tmp /bin/bash

    1. You are right. But directly mounting the disk will not work. It is a disk instead of a partition or volume. The `xm block-attach` or `xl block-attach` tools can be used to attach a virtual disk to Domain-0 and you can then mount the filesystems to edit the configuration files.

Leave a Reply

Your email address will not be published. Required fields are marked *