Xen Virtual Machine Migration (In Hyper-VM)

In this post, we will learn about how to do Xen Virtual Machine migration from one Host Base Machine to other. We hope you know how to create a Virtual Machine in Xen.

Our both host machines had the same specs and same LVM management.
Here LVM Management means in both host machine we have same no. of Hard Disk and allotment of Physical Volume was same.

Now in this scenario we want to migrate our Virtual Machine from Xen02 to Xen01.
The following are details below —

Details of Lab environment
(1) Xen Server 1 = xen01
(2) Xen Server 2 = xen02
(3) Using LVM = yes
(3) Virtual Machine Name = redtest created at xen02
(4) Migrate Virtual Machine from xen02 to xen01 ( xen02—-> xen01 )

Roadmap of this task

In this section we will discuss about the roadmap which we will follow for this migration.

(1) Make snapshot of LVM partition which you have given to you virtual Machine.

On running the command /usr/sbin/lvdisplay we found our VM was 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 Xen VM migration from Xen02 to Xen01

In this section we will walk you through how we did the Xen VM migration.

(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.

Alternatively from base Xen server machine you can shutdown the VM without login into VM.
The command is –

#(redtest is VM name ,see it from "xm list")
/usr/sbin/xm shutdown DomainName 

(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 our xen server we have command to start VM is xm create domain-name
Hence,

/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.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.