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:
vmhostis a RHEL 5 server running several virtual machines using the Xen virtualization technology. Each virtual machine is allocated a 60 GB logical volume within an LVM volume group. One of these virtual machines, “win2k3vm”, needs to be moved to a new server.new-vmhostis almost identical to vmhost, but has updated hardware and more memory. This is the server that “win2k3vm” will be moved to.
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/
Thanks for posting this. It’s incredibly useful.
Great post, this saved me a lot of time!
Here’s another (similar) way to move a LVM based VM to another host
1. create a LVM partition of the same size or larger on the target host.
lvcreate…
2. shutdown the vm on the source host
xm shutdown vm
3. copy the LVM partition to the target host using:
dd if=/dev/vg_root/lv_zimbra bs=1k | ssh zen4 dd of=/dev/vg_root/lv_zimbra bs=1k
4. copy the xen startup script for the vm to the target server:
scp /etc/xen/zimbra target:/etc/xen
Thanks! Worked great.