Everyday I learn something new about Linux-KVM, this is why I love this platform. Today we are going to talk about Live Migration. The kicker? Shared storage not required. Now please keep in mind that just because shared storage is not required, doesn’t mean there is not a benefit to it. Shared storage will accelerate this process, since the data will not have to move. However virtualization is all about flexibility and so is Linux for that matter, so why shouldn’t we be able to make the choice? That said this process is not documented by the libvirt team, as such it sounds like an “undocumented” feature. Please use this at your own risk, and for heaven’s sake please test and understand thoroughly before using this in production.
Migrating from kvmnode01 to kvmnode02, both with LVs with the same name.
On the receiving node we must create the Logical Volume which will receive the VM disk
<br /> # lvcreate -L8G kvmnode02 -n vm_vmname_boot<br />
Now assuming that on kvmnode01 (where the VM currently runs) it is hosted on LVM, we can simply create a link from the name of the sending Volume Group to the name of the receiving Volume Group. You can additionally link from a file name if the source VM is using a file backed VM.
<br /> # ln -s /dev/kvmnode02 /dev/kvmnode01<br />
Now we can begin the process of migrating the VM, which theoretically could take a very long time depending on the size of data and the amount of change that takes place. Also please keep in mind the progress which is displayed here is only the memory move progress. The disk will be moved prior to the memory move, and the progress will sit at zero for that time.
<br /> # virsh migrate --live vmname qemu+ssh://kvmnode02.allanglesit.net/system --copy-storage-all --verbose --persistent --undefinesource<br />
Finally once the move has completed you MUST edit the XML so that it references the Logical Volumes on the receiving host, instead of traversing the symlink. This is because the /dev tree will be repopulated on the next host reboot, so the symbolic link will no longer be there. If you edit the XML while the VM is running it won’t implement that change until a reboot of the guest, so it will continue to use the symlink until the guest and host are rebooted, but once the reboot happens you will be using the local LV natively, which is a good thing considering the symlink would be gone.
I am currently working on a wrapper script to roll this functionality into a simple live migration script, so watch for that.