Duplicating and Backing Up LVM Backed Xen DomU from a Remote Server

LVM’s snapshot feature enables us to duplicate an LVM backed Xen DomU in seconds inside of the same volume group. When we want to duplicate LVM backed Xen DomU from a remote server, we need to make use of LVM’s snapshot function and tools like scp and dd. Backing up the DomU is only part of the process of duplicating one DomU. We can finish the backing up work after copying DomU’s image to remote server. How to duplicate and back up LVM backed Xen DomU from remote server is introduced in this post.

Assumption and our goal:

There are Xen DomU virtual machines in LVM logical volume /dev/vg_xen/vm- on server (remote server).

Now we want to duplicate the virtual machine vm- to vm- which we want to stored in logical volume vm- in volume group vg_xen on server (local server). vm-‘s IP will be There are 6 steps to duplicate this virtual machine. If we just need to back up it, we can just use step 1 to setp 3.

1. Duplicate the LVM logical volume on remote server

We can duplicate the LVM volume group on remote server by making a snapshot of it. The snapshot is a clone of the logical volume. We can make a new logical volume vm- as the snapshot of logical volume vm-

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

Here the size of the new logical volume is 20G as the same of the original one.

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

2. Save the snapshot to image file using dd tool on remote server

We can use dd command to save a image of the new created snapshot logical volume of the DomU:

# dd if=/dev/vg_xen/vm- of=/lhome/xen-image/vm- bs=1k

This process may take several minutes or more depending on the size of the logical volume and the hard disk’s speed.

3. Copy the DomU’s image to the local server from the remote one

We can transfer the image from remote server after finishing the dd command on remote server.

# scp -c arcfour root@ /lhome/xen-image/

We set “-c arcfour” to get higher transfer speed of scp.

4. Create logical volume for the new DomU on local server

We can do this simultaneously with step 3. We create a new logical volume vm- under volume group vg_xen on local server:

# lvcreate -L20480 -n 'vm-' vg_xen

The size of the logical volume is the same as the one of the DomU in remote server.

5. Duplicate the data in the logical volume from the image

In this step, we use the dd command to copy data from the image file to the newly created logical volume:

# dd if=/lhome/xen-image/vm- of=/dev/vg_xen/vm- bs=1k

This may also take some time to finish.

6. Change the profile for new DomU on local server

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

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

The name and disk entry are changed.

7. 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-
# xm console

Or directly:

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

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

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

Change the IPADDR to from 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.

The new virtual machine vm- which is the clone of vm- except the IP and the Dom0 on top of which it is running is ready to use now. This process can be written into one script.

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

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.

3 Replies to “Duplicating and Backing Up LVM Backed Xen DomU from a Remote Server”

Leave a Reply

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