We recently moved a Xen virtual machine from one Xen host to another. The process involves simply copying across its disk partition (in this case an LVM2 partition using the device mapper) and copying across its config file:
1) Copy across the VM partition device.
On target host:
lvcreate -L10G -n vm1-disk xen
nc -l 12345 | dd of=/dev/mapper/xen-vm1--disk conv=nocreat bs=16065b
On source host:
xm shutdown vm1
dd if=/dev/mapper/vm1-disk bs=16065b | nc xen2 12345
2) Copy across the VM config file.
scp /etc/xen/vm1.cfg root@xen2:/etc/xen/
Some further explanation is probably needed for the first step. Creating the logical volume on the target host in advance ensures that the partition, once copied across, remains a block device rather than as an image file. Netcat (nc) provides a fast mechanism to transfer the partition over the ether (use SSH if you’re sensitive about your data). As for the flags to dd, the block size (bs) is set to 16065 bytes, the number of sectors in a cylinder so I’m told (it worked for me), and the nocreat flag tells dd not to overwrite the block device.
Note: remember to shutdown the VM first! This is an offline copy. If you want to minimise downtime I’m sure an LVM snapshot would work too.
