Clone KVM virtual machine with snapshots

kvm-virtualizationlibvirtvirsh

I've created a virtual machine using virt-manager and saved a snapshot of it's current state.

Now I'd like to create an exact duplicate machine with all snapshots from the first machine.

How could I accomplish that?

Best Answer

There are two parts to a VM - the disk image (or set of images in a snapshot chain) and the VM definitions.

Cloning VM definitions can be both simple and complex. For the clone to run on another host, all you need is virsh dumpxml VMNAME > VM.xml on the source; and then virsh define VM.xml on the destination host. If the clone is going to be running locally, you will have to manually edit the XML and change the UUIDs and names from the original ones, change the MACs, and pretty much anything else that can be unique to the VM, so there is no clash. Changing the disk image paths is also required obviously.

Cloning disk images is a matter of copying the files elsewhere. qemu-img is he utility you need to use to do the disk copying. Drop the image chain set into a separate folder, point the domxml at the leaf image, and it should just work.

Having said all that, you have virt-clone, a part of virt-install to take care of things for you