Tuesday, July 3, 2007

How to clone a XEN VM

Hi,

today, I will describe what is the manual process to clone a virtual machine (VM) using XEN technology. (Fedora Core 6 (FC6) is the distribution installed in the server.)

Ok, assume I want to clone the VM "os_template". The information related to this VM reside in the file "os_template" located in the "/var/lib/xen/images" directory. Be sure, the VM "os_template" is shut off. Then, make a copy of the os_template file:

dd if=/var/lib/xen/images/os_template of=/var/lib/xen/images/os_copy bs=4k

Now, extract the VM configuration:

virsh dumpxml os_template > os_template.xml

this is the os_template.xml's content:

<domain type='xen'>
<name>os_template</name>
<uuid>3ca12152be4195b1fa67a0e857b9723d</uuid>
<bootloader>/usr/bin/pygrub</bootloader>
<currentMemory>262144</currentMemory>
<memory>262144</memory>
<vcpu>1</vcpu>
<on_poweroff>destroy</on_poweroff>
<on_reboot>destroy</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<disk type='file' device='disk'>
<driver name='file'/>
<source file='/var/lib/xen/images/os_template.disk'/>
<target dev='xvda'/>
</disk>
<interface type='bridge'>
<mac address='00:16:3e:65:82:48'/>
</interface>
<console/>
</devices>
</domain>


now, modify next fields: name, uuid, source (file attribute), mac (address attribute). Save the modifications. I'll assume that the name given to your VM will be os_copy. Then, execute this commands:

virsh define os_template.xml
virsh start os_copy

The job is done!

Some relevant urls:

4 comments:

gorilla said...

Awesome tutorial. May not explain what is happening but gets you up and running in no time.

(Well after creating the copy of the disk image.)

Well done

theillien said...

You shouldn't have to dump the xml file on the template. If Fedora 6 is anything like openSUSE, the VM definition files should reside in /etc/xen/vm

Michael said...

you should use uuidgen to create the new UUID

remolibre said...

I'm using xen 3.1.2-92 and it has a very useful tool named virt-clone try it, works ok.