How to Duplicate Xen DomU Virtual Machines

Assumption: 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:

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.

Similar Posts

  • Implementation of strstr in glibc

    What is the implementation of strstr in glibc? Implementation of STRSTR in glibc (string/strstr.c): /* Return the first occurrence of NEEDLE in HAYSTACK. Return HAYSTACK if NEEDLE is empty, otherwise NULL if NEEDLE is not found in HAYSTACK. */ char * STRSTR (const char *haystack_start, const char *needle_start) { const char *haystack = haystack_start; const…

  • Xen HVM DomU configuration file

    An example of Xen HVM DomU configuration file. An example for install the OS from an ISO: name=”10.0.1.235″ vcpus=2 memory=2048 shadow_memory=8 disk=[‘file:/lhome/xen/vm-10.0.1.235/vmdisk0,xvda,w’, ‘file:/lhome/Linux-x86_64-DVD.iso,xvdc:cdrom,r’] vif=[‘bridge=xenbr0′] kernel=’/usr/lib/xen/boot/hvmloader’ builder=’hvm’ device_model=’/usr/lib64/xen/bin/qemu-dm’ extra=” vnc=1 vnclisten=”0.0.0.0″ vncpasswd=’1234567′ # vncdisplay=1 vncconsole=1 on_reboot=’restart’ on_crash=’restart’ An example for run the VM after installation: name=”10.0.1.235″ vcpus=2 memory=2048 shadow_memory=8 disk=[‘file:/lhome/xen/vm-10.0.1.235/vmdisk0,xvda,w’] vif=[‘bridge=xenbr0′] kernel=’/usr/lib/xen/boot/hvmloader’ builder=’hvm’ device_model=’/usr/lib64/xen/bin/qemu-dm’ extra=” vnc=1…

  • How to detect memory leaks of C programs in Linux?

    How to detect memory leaks of C programs in Linux? I also have access to the source code of the program. There are many posts related to this: Easy and quick tools on Linux (while not very accurate): http://blog.thewebsitepeople.org/2011/03/linux-memory-leak-detection/ Valgrind: manual and a tutorial. gperftools has the Google Heap Profiler which can checks for memory…

  • Direct multi-hop ssh connection

    How to use multi-hop ssh connection without needs to ssh multiple times? As a example, you are connecting to server.example.com through proxy.example.com from laptop.example.com as follows: laptop —-> proxy —-> server 2 possible methods: Method 1: Use the similar method as in Directly SSH to hosts using internal IPs through the gateway. Add this to…

2 Comments

  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-10.0.0.213/vmdisk0 /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 *