Xen Live Migration Of An LVM-Based Virtual Machine With iSCSI On Debian Lenny - Page 3
5 Creating Virtual Machines
We will use xen-tools to create virtual machines. xen-tools make it very easy to create virtual machines - please read this tutorial to learn more: http://www.howtoforge.com/xen_tools_xen_shell_argo.
Now we edit /etc/xen-tools/xen-tools.conf. This file contains the default values that are used by the xen-create-image script unless you specify other values on the command line. I changed the following values and left the rest untouched:
Make sure that you uncomment the lvm line and fill in the name of the volume group on the shared storage (vg_xen). At the same time make sure that the dir line is commented out!
dist specifies the distribution to be installed in the virtual machines (Debian Lenny) (there's a comment in the file that explains what distributions are currently supported).
The passwd = 1 line makes that you can specify a root password when you create a new guest domain.
In the mirror line specify a Debian mirror close to you.
Make sure you specify a gateway, netmask, and broadcast address. If you don't, and you don't specify a gateway and netmask on the command line when using xen-create-image, your guest domains won't have networking even if you specified an IP address!
It is very important that you add the line serial_device = hvc0 because otherwise your virtual machines might not boot properly!
Now let's create our first guest domain, vm1.example.com, with the IP address 192.168.0.103:
xen-create-image --hostname=vm1.example.com --size=4Gb --swap=256Mb --ip=192.168.0.103 --memory=128Mb --arch=amd64 --role=udev
server1:~# xen-create-image --hostname=vm1.example.com --size=4Gb --swap=256Mb --ip=192.168.0.103 --memory=128Mb --arch=amd64 --role=udev
As you see, the command has created two new logical volumes in the vg_xen volume group, /dev/vg_xen/vm1.example.com-disk and /dev/vg_xen/vm1.example.com-swap.
There should now be a configuration file for the vm1.example.com Xen guest in the /etc/xen directory, vm1.example.com.cfg. Because we want to migrate the Xen guest from server1 to server2 later on, we must copy that configuration file to server2:
scp /etc/xen/vm1.example.com.cfg email@example.com:/etc/xen/
Now we can start vm1.example.com:
xm create /etc/xen/vm1.example.com.cfg
5.1 Moving Existing Virtual Machines To The vg_xen Volume Group
If you want to do live migration for existing virtual machines that are not stored on the iSCSI shared storage, you must move them to the vg_xen volume group first. You can do this with dd, no matter if the guests are image- or LVM-based. This tutorial should give you the idea how to do this: Xen: How to Convert An Image-Based Guest To An LVM-Based Guest
6 Live Migration Of vm1.example.com From server1 To server2
To check if the live migration is really done "live", i.e. without interruption of the guest, you can log into vm1.example.com (e.g. with SSH) and ping another server:
This will ping google.com until you press CTRL + C. The pinging should continue even during the live migration.
should show that vm1.example.com is currently running on server1:
server1:~# xm list
Before we migrate the virtual machine to server2, we must make sure that /dev/vg_xen/vm1.example.com-disk and /dev/vg_xen/vm1.example.com-swap are available on server2:
As you see, the command shows NOT available for both volumes, so we must make them available:
Now they should be available:
should not list vm1.example.com yet on server2:
server2:~# xm list
Now we can start the live migration:
xm migrate --live vm1.example.com server2.example.com
During the migration, the pings on vm1.example.com should continue which means that the guest is running even during the migration process.
Afterwards, take a look at
server1:~# xm list
As you see, vm1.example.com isn't listed anymore on server1.
Let's check on server2:
server2:~# xm list
If everything went well, vm1.example.com should now be running on server2.