Tuesday, March 17, 2015

How to Clone a Xen Guest on LVM

DD Copy Method

Make the second LV for the cloned one:
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 bs=4096 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:
  • The name of the guest (from "guest01" to "guest02"
  • The MAC address of the guest on the "vif =" line
  • The UUID of the guest
  • The logical volume on the "disk = " line.
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

No comments:

Post a Comment