KVM: Live Migration of Virtual Machine

From DISI
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Consider a scenario where you have two active hypervisors which are running their own individual set of VMs. There may come a time when you want to migrate a virtual machine from one hypervisor to another but you don't want to interrupt the services that an active VM operates. This is where live migration comes in. With live migration, we can move a VM across two different hypervisors and still enjoy the services that VM operates.

Live Migration of Virtual Machine on CentOS6

nu is a virtual machine that operates on the hypervisor origin. I have a second hypervisor, destination where I want to migrate nu to. Nu operates nagios service and we'd like no interruptions to affect the information nagios provides us.

1) Before proceeding with the migration, we need to know the size of nu's VM image. Use qemu-img info on the VM image. Below, I can see the vm image is 16106127360 bytes. Take note of that number.

[root@origin ~]# qemu-img info /var/lib/libvirt/images/nu-disk1.qcow2
image: /var/lib/libvirt/images/nu-disk1.qcow2
file format: qcow2
virtual size: 15G (16106127360 bytes)
disk size: 16G
cluster_size: 65536

2) At the destination machine, you must create an empty disk VM image file for the VM to eventually migrate to. The migration destination for the image must be the exact location where the image was on the origin. In the origin, we can see it was at /var/lib/libvirt/images. Accordingly, we must create our empty disk VM image in /var/lib/libvirt/images.

[root@destination images]# qemu-img create -f qcow2 /var/lib/libvirt/images/nu-disk1.qcow2 16106127360

3) On origin machine, we can now begin migration to destination using 'virsh migrate --live':

 [root@origin ~]# virsh migrate --live --persistent --copy-storage-all --verbose --desturi qemu+ssh://destination/system nu
 Migration: [100 %]
 --persistent: leaves domain persistent on destination host
 --live: indicate live migration
 --copy-storage-all: indicates non-shared storage.  The entire VM disk image is copied from one machine to the other
 --verbose: display migration progress
 --desturi: connection URI of destination host.

4) On destination, you can see the migrated host will first appear under your VM list but will not be active until migration completes. The VM will continue to run on your origin.

[root@destination images]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 8     nu                             paused
 -     kappa                          shut off

5) Upon migration getting to 100%, the state of the VM should change to running:

[root@destination images]# virsh list --all
 Id    Name                           State
----------------------------------------------------
 7     alpha7                         running
 8     nu                             running
 -     kappa                          shut off