Search:  
Gentoo Wiki

HOWTO_Clone_a_Xen_VM_with_LVM

Contents

Introduction

I don't believe the open source version of Xen includes a built-in feature for making a clone of a guest operating system. However, it is simple to achieve this by using traditional disk copying methods. The two best choices are to use dd to make a copy of the guest's disk file, or to use the snapshot feature of LVM if the guest is on its own logical volume although this is not recommended for file IO intensive applications.

Before installing the first guest, a logical volume of 5000 MB was created:

lvcreate -L 5000 -n guest01 VG0

Where "VG0" is the name of the volume group and "guest01" is the name of the logical volume. During the guest creation process, /dev/VG0/guest01 was entered as the partition to use for the guest's storage space. The name "guest01" was also used as the system name of the guest.

After the guest installation is complete, the guest operating system is installed on /dev/VG0/guest01 and the configuration file that stores the guest's information for the hypervisor is housed in /etc/xen/guest01. Cloning this guest involves two steps: copying the guest's disk and creating a new configuration file.

LVM snapshot method

To clone the disk, make a snapshot of the logical volume using the following command:

lvcreate -L 5000 -s -n guest02 /dev/VG0/guest01

There should now be a second logical volume in VG0 that contains the exact same data as the first:

[root@localhost ~]# lvscan
 ACTIVE   Original '/dev/VG0/guest01' [4.91 GB] inherit
 ACTIVE   Snapshot '/dev/VG0/guest02' [4.91 GB] inherit

DD Copy Method

This method is preferred for file IO intensive applications and if perhaps more stable in the long run as both LV's arent reading from the same original and writing to different snapshots. Make the second LV:

lvcreate -L 5000 -n guest02 VG0

Then use dd to copy the contents of the first volume into the second. Be sure to shut down the guest01 VM before you begin:

xm shutdown guest01

Copy the contents of one LV into another:

dd if=/dev/VG0/guest01 of=/dev/VG0/guest02

Configure Xen

In order to make the hypervisor aware of this new guest, a new configuration file must be created. To do this, make a copy of the original configuration file:

cp /etc/xen/guest01 /etc/xen/guest02

Then, edit the new file, /etc/xen/guest02. In order for the guest to function the following lines must be changed:

Other parameters can also be changed as desired (the amount of memory for example). The MAC and the UUID are both random numbers. It is sufficient to simply change a few digits of each. Or, a utility that creates random MAC and UUID numbers can be used.

The new guest can now be started with the command:

xm create guest02 -c

The guest should immediately appear in the virt-manager GUI window and can now be used as any other guest.

Please note that this content was shamelessly liberated from a FAQ on the Red Hat website. I couldn't find any copyright info that pertained to it and since we're all friends in linux land I've added it here so we can all play.

Concerns or Compliments? Please use the Discussion section.

Retrieved from "http://www.gentoo-wiki.info/HOWTO_Clone_a_Xen_VM_with_LVM"

Last modified: Mon, 04 Aug 2008 09:54:00 +0000 Hits: 3,347