Notes on restoring kvm domains

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:

Images, /var/lib/libvirt/images

Definitions, /etc/libvirt/qemu

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.

The steps:

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.

This entry was posted in System Administration on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).