Tuesday, April 30, 2013

Xen Virtual Machine Migration (In Hyper-VM)

                           In this scenario we will discuss about how to migrate the Xen Virtual Machine from one Host Base Machine to other. I hope you know how to create a Virtual Machine in Xen. My both host machine had the same specs and same LVM management.Here LVM Management means in both host machine I have same no. of Hard Disk and allotment of Physical Volume was same. Now in this scenario I want to migrate my Virtual Machine from Xen02 to Xen01.The following are details below –

(1) Xen Server = xen01
(2) Xen Server = xen02
(3) Using LVM = yes
(3) Virtual Machine Name = redtest created at xen02
(4) Migrate Virtual Machine from xen02 to xen01 ( xen02—-> xen01 )
The Roadmap of this task –

(1) Make snapshot of LVM partition which you have given to you virtual Machine
On doing /usr/sbin/lvdisplay I found my VM is resided at /dev/xen_disks/redtest-sda
— Logical volume —
LV Name /dev/xen_disks/redtest-sda
VG Name xen_disks
LV UUID dLa1Uz-qnI2-oL50-vSgH-YZ1q-vgM3-fc0IpF
LV Write Access read/write
LV Status available
# open 0
LV Size 10.00 GB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:7
(2) Create image of snapshot by “dd” command and transfer it to xen01
(3) Create same size of LVM in xen01 as you have in xen02
(4) Transfer the VM file from xen02 to xen01 ( eg. /etc/xen/redtest )
(5) Restore the snapshot image in xen01
(6) Remove the snapshot image,LVM and Xen VM file from xen02 after successfully finishing the task.
Steps to follow for Xen VM migration from Xen02 to Xen01 =>
(1) Login into xen02 where your Virtual Machine is present.
On doing “xm list” you will see the list of Virtual machine in xen server.
# /usr/sbin/xm list
(2) Shutdown the Virtual Machine by ” init 0 ” command after login into xen02.
In other way from base Xen server machine you can shutdown the VM without login into VM.
The command is
# /usr/sbin/xm shutdown DomainName (redtest is VM name ,see it from “xm list”)
(3) After shutdown take the snapshot of LVM partition where you have your VM is installed.
/usr/sbin/lvcreate -s -L 500M -n redtest-snap /dev/xen_disks/redtest-sda
(4) Make the snapshot image :
dd if=/dev/xen_disks/redtest-snap of=redtest.img bs=4096
(5) Transfer the image file to xen01.
scp redtest.img xen01:/root
(6) Login ino Xen01 and create the same size of LVM with same name:
/usr/sbin/lvcreate -n redtest-sda –size 10G xen_disks
(7) Restore the image file -
cd /root
dd if=redtest.img of=/dev/xen_disks/redtest-sda bs=4096
(8) If you will do “xm list” you will not find your VM name in list.
Start the VM in Xen01.
In my xen server I have command to start VM “xm create domain-name“.
/usr/sbin/xm create redtest
Note: May be in your Xen server the command is “xm start Domain-name”
(9) After successful migration remove the snapshot,imagefile,LVM from xen02 according to your need.

No comments:

Post a Comment