KVM/libvirt: how to migrate between 2 hosts with different CPUs

Solution 1:

You should edit the part of the xml definition of your guest so that it contains a subset of CPU capabilities that are found in both CPUs (Intel and AMD). You can use virsh to find this subset. Here's how:

At the 1st host

$ virsh capabilities | virsh cpu-baseline /dev/stdin > /tmp/host1.xml

# copy this file to Host#2 -- e.g.:
$ scp /tmp/host1.xml $HOST2:/tmp/host1.xml

Everything else happens at the 2nd host

$ virsh capabilities | virsh cpu-baseline /dev/stdin > /tmp/host2.xml
$ cat /tmp/host1.xml /tmp/host2.xml > /tmp/both-cpus.xml

Now edit both-cpus.xml and:

  1. keep only the <cpu>....</cpu> sections
  2. from these sections remove the lines with <vendor>....</vendor>

Finally run this:

$ virsh cpu-baseline /tmp/both-cpus.xml

If you get this error "XML error: Missing CPU architecture" add <arch>x86_64</arch> in both <cpu>...</cpu> sections. Ofcourse x86_64 is for modern AMD and Intel CPUs, if you work with some other architecture adjust appropriately (thanks to harald for this tip).

The output of the above command must be used inside the xml definitions of the guest.

References

  • https://www.berrange.com/posts/2010/02/15/guest-cpu-model-configuration-in-libvirt-with-qemukvm/

  • https://www.redhat.com/archives/libvir-list/2011-March/msg01022.html