Manually migrate LVM based vm from one KVM hosts to another
We have a KVM based VM on LVM volume that we need to migrate to different host. This is not hot-live migration and will be done offline. Lets looks at steps required to get it done. There may be many different ways to do it and this is just one of them.
Both of our KVM hosts configured exactly the same. Both have volume group vm-images that hold virtual machines LVM’s
ServerA#vgdisplay --- Volume group --- VG Name vm-images System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 55 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 1 Act PV 1 VG Size 931.51 GiB PE Size 4.00 MiB Total PE 238466 Alloc PE / Size 5000 / 19.53 GiB Free PE / Size 233466 / 911.98 GiB VG UUID F8BExR-ZUTy-JzoV-HKEC-xxxx-y3ze-g4dpxp
Lest assume serverA and serverB and we need to migrate vm called DC from serverA to serverB
Step 1
Run lvdisplay on serverA to determine size of LVM used by our vm called DC
serverA#lvdisplay --- Logical volume --- LV Path /dev/vm-images/DC LV Name DC VG Name vm-images LV UUID eUYUQ0-6KF9-XXXX-4b8z-DdIb-7vLQ-8m7HTg LV Write Access read/write LV Creation host, time serverA, 2016-06-08 09:26:50 -0400 LV Status available # open 0 LV Size 39.06 GiB Current LE 10000 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2
Step 2
Note the size of LV volume from step 1 (in our case 40G) and create LVM on serverB with exactly same size and name using same Volume Group as the one on serverA (VG and name does not have to be the same. In our case it is for consistency)
serverB#lvcreate -L 40G -n DC vm-images Logical volume "DC" created.
Step 3
Shutdown your VM on serverA from VM or bu using virsh
virsh destroy DC
Step 4
Use dd with ssh to transfer Volume over to serverB. To monitor progress you can install pv
yum install pv
dd if=/dev/vm-images/DC | pv | ssh root@serverB 'dd of=/dev/vm-images/DC'
Step 5
Dump the xml definition on serverA. Run virsh list –all to find name of your vm
virsh dumpxml DC > DC.xml
Step 6
Transfer DC.xml from serverA to ServerB
serverA# scp DC.xml root@serverB:/root
Step 7
Define new vm on serverB
serverB#virsh define DC.xml
Step 8
Start new vm
serverB#virsh start DC