Off-line migration of QEMU/KVM virtual machine

Assumptions

You have 2 computers, both with Linux (Linux Mint in my case). On one computer you have a QEMU/KVM virtual machine and you want to copy/move it to the other computer. On this second computer you have already QEMU/KVM installed and ready. You want to follow an off-line migration – so the virtual machine is stopped first, then recreated on the second computer. And then you can start it again on the second computer.

Solution

  1. Stop the virtual machine on the first computer.
  2. Locate the disk image file (like .qcow2 file) used by the virtual machine on the first computer. The Virtual Machine Manager program can help here. The file will be large (usually some GBs) but you need to copy it (somehow) to the second computer.
  3. Export virtual machine definion to an XML file:
    virsh dumpxml VMNAME > my_vm.xml
    
  4. Copy the XML file to the second computer. Edit the file to update path to the disk image. Search for a tag <disk>. It should contain a tag <source> having “file” attribute – you need to update its value so it points to the disk image file copied in step 2.
  5. If the VM was attached to a custom defined networks, there are some more steps – see: https://serverfault.com/questions/434064/correct-way-to-move-kvm-vm
  6. On the second computer run:
    virsh define my_vm.xml
    
  7. Run the Virtual Machine Manager on the second computer. It should show a new virtual machine that you have just imported. Run it.

In my case the first run failed with error message “the CPU is incompatible with host CPU: Host CPU does not provide required features: xop, fma4, tbm”. I’ve solved the issue by going to the tab with virtual machine details (in Virtual Machine Manager), then going to the “Processor” section and clicking checkbox “Copy host CPU configuration”:

You can find some more information here: https://documentation.suse.com/sles/15-SP1/html/SLES-all/cha-libvirt-config-gui.html#id-1.12.4.8.9.5

Then I’ve started my virtual machine again and it was fine!

About krzysztoftomaszewski

I've got M.Sc. in software engineering. I graduated in 2005 at Institute of Computer Science, Warsaw University of Technology, Faculty of Electronics and Information Technology. I'm working on computer software design and engineering continuously since 2004.
This entry was posted in Linux and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s