Centos 7 KVM Migrating Virtual Machines

This article is about migrating virtual machines in a mixed hardware environment. I have struggled with the migration

This article is about migrating virtual machines in a mixed hardware environment. I have struggled with the migration between CPU architectures and stumbled on a solution. It’s not completely ideal, but the testing I have done with it so far seems to work.

My environment is 2 Dell servers, a Poweredge 2950 and a Poweredge T420. Both good servers and both have xeon processors but the cpu bridging is different, one is Sandy bridge and the other is ivy bridge. They are supposed to be compatible, but I have had problems in the past migrating successfully. Even with the virsh minimal command for the cpu’s, it was still a problem. Both are Centos 7 with a bridged bonded network setup. See my article “CentOS 7 KVM Hypervisor Bonded Bridged NIC’s”.

The easiest way I have found around this problem is to copy the xml file for the vm, vm_name.xml, from the /etc/libvirt/qemu directory to the target KVM host. I don’t think it’s necessary to say this, but shutdown the vm to be migrated before you begin. Something like this:

virsh shutdown vm_name


scp /etc/libvirt/qemu/vn_name.xml root@destination_kvm_host:/etc/libvirt/qemu

The next step is to copy the virtual machines disk.

scp /var/lib/libvirt/images root@destination_kvm_host:/var/lib/libvirt/images

This may take a while depending on how large the disk file is.

Next, login to the destination kvm host server and create a soft link for the xml file you just copied to the destination kvm host server:

ln -s /etc/libvirt/qemu/vm_name.xml /etc/libvirt/qemu/autostart/vm_name.xml

I’m not sure if it’s necessary but I always put an autorelabel to ensure the copy has the correct selinux context.

touch /.autorelabel

Then I reboot the destination kvm host server: reboot

Once the server is back up, run this command to ensure the vm started: virsh list –all

This shows all vm’s started or not. If the vm is running, which in my case it always has been, login to the vm you just migrated and ensure all is well.

This has worked well for me in a mixed hardware environment. My static settings have all stayed in place and the architecture adapted to the new kvm host.

There are a lot of ways to migrate between KVM hosts, but for me and my current environment, this is the easiest, most seamless and so far, most reliable method. It may not be the best or easiest for everyone, but I hope this helps someone that has faced the same issue as I have. It has saved me hours of work trying to figure out a way to migrate servers and free up resources.

One edit: I migrated a couple of vms that did not boot. The issue was cpu related. I opened the xml file on a running machine and copied the cpu config; vi /etc/libvirt/qemu/vm.xml

I copied the cpu config the the non running vm’s and another reboot of the kvm host erver solved the problem. There was one vm_port I had to remove on one of the vm’s. Use your logs if there is an issue and look at the error messages. Most of these issues were solved easily with just a text editor.

If you have a problem, please let me know.

I hope this helps.

Hits: 5

Leave a Reply