Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm a bit lost with virt-manager / libvirt / KVM.

I've got a working KVM VM (Windows XP) which works nicely.

The VM is backed by a 4GB file or so (a .img).

Now I want to do something very simple: I want to duplicate my VM.

I thought "OK, no problem, let's copy the 4GB file and copy the XML" file.

But then the libvirt FAQ states in all uppercase: "you SHOULD NOT CARE WHERE THE XML IS STORED"

http://wiki.libvirt.org/page/FAQ

OK fine, I shouldn't care. But then how do I duplicate my VM?

I want to create a new VM that is a copy of that VM.

share|improve this question

3 Answers 3

up vote 1 down vote accepted

virsh will allow your to edit, export, and import the XML definition for your servers. I would use virt-clone to generate a cloned image file, and export the XML. To be safe I would remove the clone configuration from the original server.

share|improve this answer

The most convenient is simply:

# virt-clone --connect=qemu://example.com/system -o this-vm -n that-vm --auto-clone

Which will make a copy of this-vm, named that-vm, and takes care of duplicating storage devices. Nothing new here except detail.

More to the point, What the FAQ is saying is that the XML domain descriptions are not directly editable, you need to go through libvirt. To complete the steps taken by the virt-clone command, you could:

# You cannot "clone" a running vm, stop it.  suspend and destroy
# are also valid options for less graceful cloning
virsh shutdown this.vm

# copy the storage.
cp /var/lib/libvirt/images/{this-vm,that-vm}.img

# dump the xml for the original
virsh dumpxml this-vm > /tmp/that-vm.xml

# hardware addresses need to be removed, libvirt will assign
# new addresses automatically
sed -i /uuid/d /tmp/that-vm.xml
sed -i '/mac address/d' /tmp/that-vm.xml

# and actually rename the vm: (this also updates the storage path)
sed -i s/this-vm/that-vm /tmp/that-vm.xml

# finally, create the new vm
virsh define /tmp/that-vm.xml
virsh start this-vm
virsh start that-vm
share|improve this answer
    
This works also for copy over a VM to another host: use sftp instead of cp, (possible) change the image path before 'defining' the new vm and sftp also the that-vm.xml to the other host. –  Andreas Florath Jul 28 '13 at 15:58
    
Thanks for this, saved me a bunch of time. The problem I had is cloning vs creating new, in that if I create a new node, the package versions would be out of sync with the other nodes which used a local mirror. –  Mike Purcell Aug 14 at 22:43

Apparently virt-clone is the way to go.

I tried duplicating the XML but it wouldn't appear under virt-manager.

I still wonder how I can transfer an XML + .img to a new system that said...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.