In the past, I have been using the immensely useful virt-backup.pl script to migrate a LVM-based (raw volume) Linux KVM guest from one host to another. However, there is an even easier way to cold-migrate a KVM guest. This approach is particularly helpful if there’s not enough disk space on the host to create a gzipped backup of the logical volume using the
Here’s how it works:
lvcreateto create the new logical volume on the destination host with the same size as the source logical volume. Use the
lvdisplaycommand to find out the required size.
virsh shutdownthe source KVM guest
- On the source host:
screen dd if=/dev/vg_ssd/lv_vm_wopr | pv | ssh -C root@desthost dd of=/dev/vg0/lv_vm_wopr
- Wait until finished
I’m using the
screen command so it will continue running in the background once I close the
ssh session on the source host. Use CTRL-A-D to background a
screen session and
screen -dr to bring it back up.
ssh makes sure the entire transfer is encrypted. The -C parameter makes sure the content will be compressed which may speed up the transfer considerably (or not, on a slow CPU). Obviously, the new KVM guest has to be
virsh define‘d on the destination based on the
virsh dumpxml configuration data from the source host.