Manual Migration of LVM-based Guest Between Hosts

How to manually migrate a virtual machine from one host to another. The process is roughly: copy the guest config to the destination, create LVs on the destination, dd the LVs across ssh, instantiate and start the guest on the destination.

As I described in a previous post, I dedicate an LV in the host for each guest. The guest then uses LVM to manage the space. In this case the guest is contained in two logical volumes on the host.

This example moves vm the guest "f10-Guest" from source host src-host to destination host dest-host.

Source

Export the XML guest config and copy it to the new host.

 [root@src-host etc]# virsh dumpxml f10-Guest \
    > /var/lib/libvirt/images/f10-Guest.xml
 [root@src-host etc]# scp /var/lib/libvirt/images/f10-Guest.xml \
    dest-host:/var/lib/libvirt/images/

Discover the storage used by the guest. See libvirt docs for help on finding the volume definition.

Example:

 <devices>
    <disk type='block' device='disk'>
      <driver name='phy'/>
      <source dev='/dev/VGSanLun10/LVDomUAA0049DF8734'/>
      <target dev='xvda' bus='xen'/>
    </disk>
    ...

Find the sizes and names of the volumes holding the guest. In my case I know they all contain 'VGSan'.

 [root@src-host etc]# virsh dumpxml f10-Guest | grep VGSan
      <source dev='/dev/VGSanLun10/LVDomUAA0049DF8734'/>
      <source dev='/dev/VGSanLun11/LVExlSfx'/>
  [root@src-host etc]# lvs /dev/VGSanLun10/LVDomUAA0049DF8734
  LV                 VG         Attr   LSize  Origin Snap%  Move Log Copy%
  LVDomUAA0049DF8734 VGSanLun10 -wi-ao 25.00G
  [root@src-host etc]# lvs /dev/VGSanLun11/LVExlSfx
  LV       VG         Attr   LSize  Origin Snap%  Move Log Copy%
  LVExlSfx VGSanLun11 -wi-a- 20.00G

Destination

Create LVs to contain the VM.

 [root@dest-host ~]# lvcreate --size 20G --name LVExlSfx VGRAID
  Logical volume "LVExlSfx" created
 [root@dest-host ~]# lvcreate --size 25G --name LVDomUAA0049DF8734 VGRAID
  Logical volume "LVDomUAA0049DF8734" created

Source

Copy disk images to destination hardware.

 [root@src-host images]# virsh shutdown f10-Guest
 [root@src-host images]# dd if=/dev/VGSanLun10/LVDomUAA0049DF8734 \
   | ssh -c blowfish root@dest-host "dd of=/dev/VGRAID/LVDomUAA0049DF8734"
 [root@src-host images]# dd if=/dev/VGSanLun11/LVExlSfx \
   | ssh -c blowfish root@dest-host "dd of=/dev/VGRAID/LVExlSfx"

Destination

Update disk locations in XML config.

 [root@dest-host images]# cd /var/lib/libvirt/images
 [root@dest-host images]# sed -e 's/VGSanLun10/VGRAID/' \
     -e 's/VGSanLun11/VGRAID/' < f10-Guest.xml > tmp.xx
 [root@dest-host images]# mv tmp.xx f10-Guest.xml 

Define VM from XML config and start it.

 [root@dest-host images]# virsh define /var/lib/libvirt/images/f10-Guest.xml
 [root@dest-host images]# virsh start f10-Guest

Syndicate

Subscribe to Syndicate