Move an LVM-based virtual machine to another host

For those running Xen on servers with no back-end SAN, the following instructions detail the steps necessary to move an LVM-based virtual machine to a new physical host. There may be more elegant ways to achieve this, but this is what worked for me.

Environment
Ok, so let’s set the scene:


Migrate the Virtual Machine
1. Create a snapshot of virtual machine LVM volume. This can be run on a live virtual machine, but it is probably safer to perform a graceful shutdown of your virtual machine first.

[root@vmhost]# lvcreate -s -L 300m -n win2k3vm-snap VolGroup01

2. Export the snapshot of the guest VM to a file that can be moved between physical servers.

[root@vmhost]# dd if=/dev/VolGroup01/win2k3vm-snap of=/mnt/temp/win2k3vm.img bs=4096

3. Remove the snapshot LVM volume.

[root@vmhost]# lvremove /dev/VolGroup01/win2k3vm-snap

4. Copy the file to the new VM host. Make sure you have sufficient free drive space.

[root@vmhost]# scp /mnt/temp/win2k3vm.img user@new-vmhost:/mnt/temp/

5. On the new VM host, create an LVM volume that is at least as big as the guest VM file.

[root@new-vmhost]# lvcreate -n win2k3vm -L 60G VMGroup

6. Transfer the guest VM file to the new LVM volume.

[root@new-vmhost]# dd if=win2k3vm.img of=/dev/VMGroup/win2k3vm bs=4096

7. Copy the VM config file from the old VM host to the new VM host server.

[root@vmhost]# scp /etc/xen/win2k3vm user@new-vmhost:

8. Copy the file to the appropriate directory.

[usr@new-vmhost]$ sudo mv ~/win2k3vm /etc/xen/

Summary of Commands
[root@vmhost]# lvcreate -s -L 300m -n win2k3vm-snap VolGroup01
[root@vmhost]# dd if=/dev/VolGroup01/win2k3vm-snap of=/mnt/temp/win2k3vm.img bs=4096
[root@vmhost]# lvremove /dev/VolGroup01/win2k3vm-snap
[root@vmhost]# scp /mnt/temp/win2k3vm.img user@new-vmhost:/mnt/temp/
[root@new-vmhost]# lvcreate -n win2k3vm -L 60G VMGroup
[root@new-vmhost]# dd if=win2k3vm.img of=/dev/VMGroup/win2k3vm bs=4096
[root@vmhost]# scp /etc/xen/win2k3vm user@new-vmhost:
[usr@new-vmhost]$ sudo mv ~/win2k3vm /etc/xen/

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

Thanks for posting this. It’s incredibly useful.

Leave a comment

(required)

(required)