Migrate a KVM Virtual Machine to another server manually using 'dd' on LVM


Written by Dennis Nind

Last published at: February 8th, 2019

We needed to migrate some servers from a Proxmox node, to a Virtualizor node without data-loss. 

To do this, we needed to first create the same specification server on the Virtualizor (destination) node, then move the VM's disk image over to the new server using 'dd' (scp won't work, as its an unmounted / non-standard file type). 

You can get the destination of the image file by running 'lvscan', or 'lvscan | grep vmid' - this will return the file path of the VM. 

For example, /dev/vg/filename One thing we did notice was that the file itself was a symlink to an alternative location... 

lrwxrwxrwx 1 root root 7 Oct 29 14:23 vsv1044-dzwctmqemirzrgyo-7yv2fbuw8mh8xcdf -> ../dm-7 

As you can see, the physical location of the image is /dev/dm-7 (which would of course vary depending on the VM). 

For the newly created VM on the destination server, we checked the same which gave us the 'from' and 'to' location to replace the image... 

lrwxrwxrwx 1 root root 7 Oct 29 20:15 vsv1043-dwcjezrbtmhdza5p-geaqlscnbmufxf3y -> ../dm-5 

To initiate the copy / migration, we first 'shutdown' the VM from the destination node, then ran the following... 

NOTE: The dd command is 'from', then 'to' - the source, then the destination server... dd if=/dev/dm-7 | ssh destination-ip dd of=/dev/dm-5 

This runs without verbose, so will take some time to copy the image - as such, it may be worth running this in 'screen' to ensure there are no issues with disconnectivity throughout the process. 

Once done, simply login to the Virtualizor control panel (or any KVM control panel) to start the new machine. 

NOTE: We did notice that once the machine had been moved, we struggled to get a ping response. As such, we used NoVNC to connect to the machine, then manually modified the networking configuration. On doing this a second time, we found that the same could be achieved by simply running 'shutdown' from Virtualizor (which forces the config to be intact), then started again and the migration was complete.