Xen Live Migration Of An LVM-Based Virtual Machine With iSCSI On Debian Lenny

Version 1.0
Author: Falko Timme

This guide explains how you can do a live migration of an LVM-based virtual machine (domU) from one Xen host to the other. I will use iSCSI to provide shared storage for the virtual machines in this tutorial. Both Xen hosts and the iSCSI target are running on Debian Lenny in this article.

I do not issue any guarantee that this will work for you!


1 Preliminary Note

I'm using the following systems here:

  • Xen host 1 : server.example.com, IP address:
  • Xen host 2 : server2.example.com, IP address:
  • iSCSI target (shared storage): iscsi.example.com, IP address:
  • virtual machine: vm1.example.com, IP address:

I will use LVM on the shared storage so that I can create/use LVM-based Xen guests.

The two Xen hosts and the iSCSI target should have the following lines in /etc/hosts (unless you have a DNS server that resolves the hostnames):

vi /etc/hosts       localhost.localdomain   localhost   server1.example.com     server1   server2.example.com     server2   iscsi.example.com       iscsi   vm1.example.com         vm1


2 Xen Setup


The two Xen hosts should be set up according to chapter two of this tutorial: Virtualization With Xen On Debian Lenny (AMD64)

To allow live migration of virtual machines, we must enable the following settings in /etc/xen/xend-config.sxp...

vi /etc/xen/xend-config.sxp
(xend-relocation-server yes)
(xend-relocation-port 8002)
(xend-relocation-address '')
(xend-relocation-hosts-allow '')

... and restart Xen:

/etc/init.d/xend restart


3 Setting Up The iSCSI Target (Shared Storage)


Now we set up the target. The target will provide shared storage for server1 and server2, i.e., the virtual Xen machines will be stored on the shared storage.

aptitude install iscsitarget iscsitarget-modules-`uname -r`

Open /etc/default/iscsitarget...

vi /etc/default/iscsitarget

... and set ISCSITARGET_ENABLE to true:


We can use unused logical volumes, image files, hard drives (e.g. /dev/sdb), hard drive partitions (e.g. /dev/sdb1) or RAID devices (e.g. /dev/md0) for the storage. In this example I will create a logical volume of 20GB named storage_lun1 in the volume group vg0:

lvcreate -L20G -n storage_lun1 vg0 

(If you want to use an image file, you can create it as follows:

mkdir /storage
dd if=/dev/zero of=/storage/lun1.img bs=1024k count=20000

This creates the image file /storage/lun1.img with a size of 20GB.


Next we edit /etc/ietd.conf...

vi /etc/ietd.conf

... and comment out everything in that file. At the end we add the following stanza:

Target iqn.2001-04.com.example:storage.lun1
        IncomingUser someuser secret
        Lun 0 Path=/dev/vg0/storage_lun1,Type=fileio
        Alias LUN1
        #MaxConnections  6

The target name must be a globally unique name, the iSCSI standard defines the "iSCSI Qualified Name" as follows: iqn.yyyy-mm.<reversed domain name>[:identifier]; yyyy-mm is the date at which the domain is valid; the identifier is freely selectable. The IncomingUser line contains a username and a password so that only the initiators (clients) that provide this username and password can log in and use the storage device; if you don't need authentication, don't specify a username and password in the IncomingUser line. In the Lun line, we must specify the full path to the storage device (e.g. /dev/vg0/storage_lun1, /storage/lun1.img, /dev/sdb, etc.).

Now we tell the target that we want to allow connections to the device iqn.2001-04.com.example:storage.lun1 from the IP address (server1.example.com) and (server2.example.com)...

vi /etc/initiators.allow

... and start the target:

/etc/init.d/iscsitarget start 
Share this page:

5 Comment(s)