Before a recent rebuild, I had several kvm guests set up on one host. The rebuild, of course, wiped out their configurations. Here are my notes on how I restored them.
There are two basic components to every kvm guest on Linux. The virtual disk image file, and the guest (a/k/a domain) definition file.
The default locations for these on Red Hat inspired hosts are as follows:
Disk images can have any extension, but most often it is .img (file types also vary, I usually use qcow2). Definitions usually have the same name as the corresponding .img file, but with an .xml extension. So guest test01 would have a test01.img disk file and test01.xml definition file.
On my hosts I add a second virtual file system for my guest images that resides on a bigger disk than the default image directory.
It is important to back both these locations up because without both you won’t be able to restore your guests.
When restoring guests to the same machine or moving to another machine you need to either set them up exactly the same as the original host or modify the guest xml definition file to reflect the differences. The most important parameter to get right is the full path of the disk image found in the devices branch of the configuration. Most other things can be modified later in a gui like the Virtual Machine Manager once the guest has been restored.
1. Copy all virtual disk images to your images directory (default is /var/lib/libvirt/images).
2. Copy all saved xml definition files to the configuration directory (default is /etc/libvirt/qemu).
3. Edit the definition files to conform virtual disk image paths to their actual location (if different from the originals).
4. Import the definition files.
[root@mine ~]# virsh define /etc/libvirt/qemu/test01.xml Domain test01 defined from /etc/libvirt/qemu/test01.xml
5. Modify guest configuration as needed, like those for network devices (my previous host had included a bridge device for routing guests to my local network, in the new setup they’ll all live on the default virtual network).
6. Start the guest to test.