Saturday, February 14, 2015

migrate KVM virtual machines

  1. Create the logical volume on the target. It should be the same size as the source volume.
  2. Run nc -l 1234 | dd of=/dev/<vgname>/<lvname> on the target host. This tells netcat to listen on the network port and pipe everything to the logical volume.
  3. Shutdown the source machine cleanly to write everything to disk.
  4. Run dd if=/dev/<vgname>/<lvname> | nc <targetip> 1234 on the source host. This tells netcat to pipe everything over the network to the target host.
  5. Go fetch a cup of coffee. This takes a few minutes depending on your volume size and network speed.
  6. Copy the xml definitions from /etc/libvirt/qemu/ from the source to the target.
  7. Edit the storage portion of the xml file and any other necessary bits such as network bridge name if they are different.
  8. Reload libvirt on the target to read the xml. An /etc/init.d/libvirt-bin reload should do the trick (or systemctl restart libvirtd for distributions that use systemd)
  9. Start-up the machine on the target host.

No comments: