Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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"

libvirt 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
up vote 2 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 '14 at 22:43

Other than "virt-clone" you can duplicate the VM this way:

  1. Ensure that existing VM (to be duplicated) is shut down.
  2. do a "sudo virsh dumpxml < domid >" of the existing VM, and save the output xml file.
  3. Modify the < name > tag under the < domain > tag.
  4. Use "uuidgen" to generate a new unique ID, and use that to modify the existing < uuid > tag.
  5. Make a copy of the existing qcow virtual images which the VM uses, (usually stored in /var/lib/libvirt/images, but to be sure just read your XML file for exact location). Command is "sudo cp /var/lib/libvirt/images/xxx.qcow2 yyyy.qcow2", and fill in the new file yyyy.qcow2 in XML file.
  6. Start the new vm: sudo virsh define new.xml
  7. Start the new domid: sudo virsh start < new_domid >

share|improve this answer

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

The following command worked for me (Have to shutdown VSA/Vm before running the command)

# virt-clone --connect=qemu:///system -o present_vsa/vm_name -n vsa/vm_to_be_cloned_name --auto-clone
share|improve this answer
Aside from the pseudo VM names, this is identical to the command from the three-year-old answer — but lacking the supplemental information from that answer. – G-Man Apr 21 '15 at 7:19

Your Answer


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.