Duplicating LVM Backed Xen DomU

LVM’s snapshot feature enables us to duplicate an LVM backed Xen DomU in seconds rather than minutes. We no longer need to copy the entire file system image like backing up file backed Xen DomU. We just need to make a snapshot of the current Xen DomU in seconds. When there are changes to the file system of the new DomU, LVM will make a copy of the physical block of the logical volume write the the new volume. How to duplicate LVM backed Xen DomU is introduced in this post.

Assumption:

There are Xen DomU virtual machines in LVM logical volume /dev/vg_xen/vm-10.0.0.123/.

Now we want to duplicate the virtual machine vm-10.0.0.123 to vm-10.0.0.124 which we want to stored in logical volume vm-10.0.0.124 in volume group vg_xen. vm-10.0.0.124‘s IP will be 10.0.0.124. There are three steps to duplicate this virtual machine:

1) Duplicate the LVM logical volume

We can duplicate the LVM volume group by making a snapshot of it. The snapshot is a clone of the logical volume. We can make a new logical volume vm-10.0.0.124 as the snapshot of logical volume vm-10.0.0.123:

# lvcreate -L20480 -s -n 'vm-10.0.0.124' /dev/vg_xen/vm-10.0.0.123

Here the size of the new logical volume is 20G as the same of the original one. We may change the content in all the storage space in the new DomU so we create a logical volume that has the same size.

Here we should make sure that vm-10.0.0.123 is power off to avoid the situation there are “write” that is still in DomU’s cache.

2) Change the profile for new DomU

After making the clone of the VBD. We can create a profile for the new DomU. This is the content of /lhome/xen/vm-10.0.0.124/vm.run:

name="10.0.0.124"
cpus=2
memory=2048
disk=['phy:vg_xen/vm-10.0.0.124,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

We can start the new DomU and enter it’s console:

# xm create /lhome/xen/vm-10.0.0.124/vm.run
# xm console 10.0.0.213

Or directly:

# xm create -c /lhome/xen/vm-10.0.0.124/vm.run

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

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

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

The new virtual machine vm-10.0.0.124 which is the clone of vm-10.0.0.123 except the IP is running now. This process can be written into one script and the overall time for duplicating the Xen DomU can be as short as number of seconds.

For more tutorials about Xen, please refer to Xen Solution.

Eric Ma

Eric is a 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 comments:

  1. Hi Eric,

    Actually we can make some changes at original or old domu and it won’t make some changes to the new domu or snapshot. I had tried it, when I made the old domu shutdown then start the snapshot. All changes I made on the old domu didn’t happen at the snapshot.

    Best regards.

Leave a Reply

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