KVM / QEMU


Copying a Guest

You can have KVM clone a guest making a new image with some minor changes made. If you want an exact copy of a guest you can do that manually as well. Note that you should NOT run both the original guest and the copied image at the same time as they will be using identically identified resources - for example MAC IDs will match each other. If you wish to run a copied guest at the same time as the original guest you need to change the MAC ID as well as any IP addresses defined in the guest.

Shutdown your guests and virtual machine manager if running.

Locate the guest image and copy it to a new name. The location of guests is system dependent. If you have not altered the location check this directory first: /var/lib/libvirt/images

Copy the guest image to a new name. For example, suppose you have installed a Windows 7 guest and wish to leave that untouched and run from a copy of the guest. This allows you to start over should a problem arise due to installing software on the guest image.
cp Win7VirginInstall.img Win7Testing.img

Now locate the xml configuration file for your guest. This is probably in directory /etc/libvirt/qemu

Copy the configuration file to some other location with a matching new name:
cp Win7VirginInstall.xml /tmp/Win7Testing.xml

Edit that new xml file making some changes:
Change <name> to match the new guest name.
Change <uuid>. The change is not important, just make it different than any other on your system.
Change <source file= to reference the new guest name.

Use the virsh create command to build a new configuration file for the guest.
virsh define /tmp/Win7Testing.xml

In some cases you may need to restart the libvirtd service.
This is normally not needed when using the virsh command line.
Use ONE of these commands depending on your operating system:
service libvirtd restart
systemctl restart libvirtd.service

You should now see a new guest available:
virsh list --all

A similar technique can be used to temporarily run a copy of a guest by making an LVM snapshot of a guest image and then running:
virsh create newguest.xml

This will start a new guest image but will not copy the xml file to the libvirt/qemu directory.