How to Duplicate Xen DomU Virtual Machines
Posted on In VirtualizationAssumption: There are VBD based Xen DomU virtual machines stored under /home/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:
Table of Contents
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 **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-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:/home/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 /home/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.
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-10.0.0.213/vmdisk0 /mnt/tmp
chroot /mnt/tmp /bin/bash
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.