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: vm0-f11.run (The configuration file) and vmdisk0 (The virtual disk).

Now we want to duplicate the virtual machine vm0 stored under vm-f11-sample to vm-10.0.0.213 which is stored under vm-10.0.0.213. And vm-10.0.0.213′s ip will be 10.0.0.213. The steps to duplicate this virtual machine:

1) Duplicate the virtual disk and configuration files

# cp -rv vm-f11-sample vm-10.0.0.213

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-10.0.0.213. And here we should make sure that vm0 is power 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-10.0.0.213
# mv vm0-f11.run vm.run
# vim vm.run

This is the content of vm.run:

name="10.0.0.213"
memory=1024
disk = ['file:/lhome/xen/vm-10.0.0.213/vmdisk0,xvda,w' ]
vif = [ 'bridge=eth0' ]
bootloader = "/usr/bin/pygrub"
vcpus=2
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-10.0.0.213/vm.run
# xm console 10.0.0.213

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

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

Change the IPADDR to 10.0.0.213. 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-10.0.0.213 and then use “Ctrl + ]” to exit the xm console.

Reset vm-10.0.0.213 on Dom0:

#xm reset 10.0.0.213

The new virtual machine vm-10.0.0.213 is running now.

Updated on Feb. 10, 2010. Format the text.
Updated on Feb. 8, 2010. Change loopback backed driver to blktap backed one.
Updated on Feb. 23, 2010. Change some typo and format.
Updated on Apr. 16, 2010. Format the text.
Updated on Sep. 11, 2010. Change the VM name and directory.

Author: Zhiqiang Ma Posted on: Jan 13, 2010 Views: 2,230
Tags: , ,
Like this post? Subscribe full-text feeds from all Fclose.com blogs:
Add your comments, share your thoughts

Be nice. Keep it clean. Stay on topic. No spam.