KVM On Ubuntu - KVM Logo

KVM Offline Migration

As a follow on from the earlier series of articles on setting up KVM on Ubuntu 14.04 this article discusses performing an offline migration of a guest. Why offline rather than online? Online migration is fairly simple if you have shared storage but it starts to get awkward without. From what I’ve read an online migration without shared storage is possible but it’s fraught with danger and after trying to get it to work correctly for a couple of hours I gave up and performed an offline migration.

The main downside to a KVM offline migration is that you suffer a small amount of downtime – the time it takes to stop the guest, copy the disks and reboot the guest – which isn’t an issue for me.

In this example I’m migrating the Windows XP guest that I set up in an earlier article. The migration is carried out as follows.

KVM Offline Migration – On the Current Host

  • Stop the machine to be moved:virsh shutdown WinXP
  • Copy the HDD image of the guest to the new host:sudo scp /var/lib/libvirt/images/WinXP.img [email protected]:/home/username/WinXP.img  Note: you may need to place the image somewhere other than it’s final location on the destination due to the folder permissions of /var/lib/libvirt/images.
  • Dump the configuration file: virsh dumpxml WinXP –migratable > WinXP.xml
  • Copy the configuration file of the guest to the new host.

KVM Offline Migration – On the New Host

  • If necessary (probably will be) move the HDD image of the guest to the /var/lib/libvirt/images directory and set owner and group to root as per the old host:
    • cd /var/lib/libvirt/images
    • sudo mv /home/username/WinXP.img .
    • sudo chown root:root WinXP.img
  • Create the guest in the new host using either:
    • virsh create WinXP.xml
    • virsh define WinXP.xml

If you use the “create” command the guest will be created and started in a single operation but it will disappear when it is shut down. With the “define” command the guest will be defined but left in a shut down state however it will be permanently added to the host. To start the guest you then just use: “virsh start WinXP”.

My two hosts have slightly different network set ups so I had to tweak the configuration file before I could create the guest on the new host. It was simply a matter of changing the “interface > source > network” from br0 to default.