Top Banner
saulparada 1 VIRTUALIZATION WITH XEN ON DEBIAN 5.0.1 INSTALLATION AND CONFIGURATION TUTORIAL This tutorial explains how to install and use XEN for creating and running virtual machines on a Debian Lenny Linux Distribution. It will be explained how to set up image-based virtual machines. Preliminary Note Throughout this tutorial is used a machine with Debian Lenny 5.0.1 with hostname server.saulparada.com and IP address 192.168.72.128 as host system (dom0). Is also used Debian (Etch) for the virtual machines (domU) as well. Because almost all steps from this tutorial require root privileges, can be either precede all commands in this tutorial with the string sudo, or become root right at the beginning by typing: $ sudo –i NOTE: XEN 3.4.0 comes with the kernel 2.6.18 which is pretty old. If is using new hardware, the system might not boot anymore due to missing drivers. Installing XEN Before install XEN, must be installed some pre-requisites: # apt-get install make gcc libc6-dev zlib1g-dev python python-dev python-twisted bridge-utils iproute libcurl3 libcurl3-dev bzip2 module-init-tools transfig tgif libncurses5-dev patch libvncserver-dev libsdl- dev libjpeg62-dev bcc bin86 gawk pciutils-dev mercurial build-essential Next is downloaded XEN 3.4.0 and uncompressed it: # cd /usr/src # wget http://bits.xensource.com/oss-xen/release/3.4.0/xen-3.4.0-xen.tar.gz # tar -xvzf xen-3.4.0-xen.tar.gz # cd xen-3.4.0 Now is built it as follows: # make world && make dist This can take some time, so please be patient. Afterwards, is installed XEN: # ./install.sh
9

Virtualization With XEN on Debian 5.0.1 Installation and Configuration Tutorial

Nov 15, 2014

Download

Documents

saulparada

Virtualization With XEN on Debian 5.0.1 Installation and Configuration Tutorial
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Virtualization With XEN on Debian 5.0.1 Installation and Configuration Tutorial

saulparada 1

VIRTUALIZATION WITH XEN ON DEBIAN 5.0.1

INSTALLATION AND CONFIGURATION TUTORIAL This tutorial explains how to install and use XEN for creating and running virtual machines on a

Debian Lenny Linux Distribution. It will be explained how to set up image-based virtual machines.

Preliminary Note

Throughout this tutorial is used a machine with Debian Lenny 5.0.1 with hostname server.saulparada.com and IP address 192.168.72.128 as host system (dom0). Is also used Debian (Etch) for the virtual machines (domU) as well.

Because almost all steps from this tutorial require root privileges, can be either precede all commands in this tutorial with the string sudo, or become root right at the beginning by typing:

$ sudo –i

NOTE: XEN 3.4.0 comes with the kernel 2.6.18 which is pretty old. If is using new hardware, the

system might not boot anymore due to missing drivers.

Installing XEN

Before install XEN, must be installed some pre-requisites:

# apt-get install make gcc libc6-dev zlib1g-dev python python-dev python-twisted bridge-utils iproute libcurl3 libcurl3-dev bzip2 module-init-tools transfig tgif libncurses5-dev patch libvncserver-dev libsdl-dev libjpeg62-dev bcc bin86 gawk pciutils-dev mercurial build-essential

Next is downloaded XEN 3.4.0 and uncompressed it:

# cd /usr/src # wget http://bits.xensource.com/oss-xen/release/3.4.0/xen-3.4.0-xen.tar.gz # tar -xvzf xen-3.4.0-xen.tar.gz # cd xen-3.4.0

Now is built it as follows:

# make world && make dist This can take some time, so please be patient. Afterwards, is installed XEN:

# ./install.sh

Page 2: Virtualization With XEN on Debian 5.0.1 Installation and Configuration Tutorial

saulparada 2

The output should look as follows:

saulparada:/usr/src/xen-3.4.0# ./install.sh Installing Xen from './dist/install' to '/'... - installing for udev-based system - modifying permissions All done. Checking to see whether prerequisite tools are installed... Xen CHECK-INSTALL Wed Jun 24 04:00:38 CEST 2009 Checking check_brctl: OK Checking check_crypto_lib: OK Checking check_curl: unused, OK Checking check_iproute: OK Checking check_python: OK Checking check_python_xml: OK Checking check_udev: OK Checking check_xml2: unused, OK Checking check_zlib_lib: OK All done.

Now must be created the system start up links for XEN:

# update-rc.d xend defaults 20 21 # update-rc.d xendomains defaults 21 20

Afterwards, must be open "/etc/modules" and make sure that it has the line loop max_loop=64 in it:

# nano /etc/modules

[...] loop max_loop=64

Now let's take a look at the "/boot" directory:

# ls -l /boot/

saulparada:/usr/src/xen-3.4.0# ls -l /boot/ total 24468 -rw-r--r-- 1 root root 66583 2009-06-24 03:57 config-2.6.18.8-xen -rw-r--r-- 1 root root 91640 2009-05-28 21:41 config-2.6.26-2-686 drwxr-xr-x 2 root root 4096 2009-06-24 02:23 grub -rw-r--r-- 1 root root 6180410 2009-06-24 02:20 initrd.img-2.6.26-2-686 -rw-r--r-- 1 root root 6182211 2009-06-24 02:20 initrd.img-2.6.26-2-686.bak -rw-r--r-- 1 root root 748030 2009-06-24 03:57 System.map-2.6.18.8-xen -rw-r--r-- 1 root root 927984 2009-05-28 21:41 System.map-2.6.26-2-686 -rw-r--r-- 1 root root 1574745 2009-06-24 03:57 vmlinuz-2.6.18.8-xen -rw-r--r-- 1 root root 1506064 2009-05-28 21:40 vmlinuz-2.6.26-2-686

Page 3: Virtualization With XEN on Debian 5.0.1 Installation and Configuration Tutorial

saulparada 3

-rw-r--r-- 1 root root 495535 2009-06-24 03:48 xen-3.4.0.gz lrwxrwxrwx 1 root root 12 2009-06-24 04:00 xen-3.4.gz -> xen-3.4.0.gz lrwxrwxrwx 1 root root 12 2009-06-24 04:00 xen-3.gz -> xen-3.4.0.gz lrwxrwxrwx 1 root root 12 2009-06-24 04:00 xen.gz -> xen-3.4.0.gz -rw-r--r-- 1 root root 7196570 2009-06-24 03:48 xen-syms-3.4.0

As can be seen, there is a new kernel, 2.6.18.8-xen, but no ramdisk for it; therefore must be built

one...

# depmod 2.6.18.8-xen # update-initramfs -c -k 2.6.18.8-xen

...and update the bootloader:

# update-grub Now must be rebooted the system:

# reboot After login into the system again, by running the instruction uname –r the new XEN kernel should

show up:

# uname -r

saulparada:~# uname –r 2.6.18.8-xen

Installing XEN-TOOLS

It will be used xen-tools to create virtual machines. xen-tools make it very easy to create virtual machines. Should not be installed the xen-tools package from the Debian repository (because it is quite old), but directly from the repository of the developer in order to get the newest version.

For that must be edited the archive "/etc/apt/sources.list"...

# nano /etc/apt/sources.list ...adding the following line:

[...] deb http://apt.steve.org.uk/etch etch main non-free contrib

Then must be preformed the following commands to update the packets list and install xen-tools:

# wget -q http://apt.steve.org.uk/apt-key.gpg -O- | apt-key add - && apt-get update # apt-get install xen-tools

Page 4: Virtualization With XEN on Debian 5.0.1 Installation and Configuration Tutorial

saulparada 4

Creating Image-Based Virtual Machines

Now must be edited the file "/etc/xen-tools/xen-tools.conf". This file contains the default values that are used by the xen-create-image script unless are specified other values on the command line. I personally choose to change the following values and left the rest untouched:

# nano /etc/xen-tools/xen-tools.conf

[...] dir = /home/xen [...] dist = etch # Default distribution to install. [...] gateway = 192.168.72.1 netmask = 255.255.255.0 broadcast = 192.168.72.255 [...] passwd = 1 [...] kernel = /boot/vmlinuz-`uname -r` initrd = /boot/initrd.img-`uname -r` [...] mirror = http://ftp.cz.debian.org/debian/ [...] serial_device = hvc0 #default [...] disk_device = xvda #default [...]

The dir line specifies where the virtual machine images will be stored. dist specifies the distribution

to be installed in the virtual machines (there is a commente 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 should be specified the closest Debian mirror.

Make sure it is specified a gateway, netmask and broadcast address. If are not specified a gateway and netmask on the command line when using xen-create-image, the guest domains will not have networking even if is specified an IP address.

It is very important that is added the line serial_device = hvc0 (or serial_device = xvc0) because otherwise the virtual machines might not boot properly.

Before go on, must be created the directory where the virtual machine images should be stored:

# mkdir /home/xen Now let's create the first guest domain, xen1.saulparada.com, with the IP address 192.168.72.130:

# xen-create-image --hostname=xen1.saulparada.com --size=4Gb --swap=256Mb --ip=192.168.72.130 --memory=128Mb --arch=i386 --role=udev

Page 5: Virtualization With XEN on Debian 5.0.1 Installation and Configuration Tutorial

saulparada 5

The xen-create-image command will now create the xen1.example.com virtual machine. This can take a few minutes. The output should be similar to this one:

saulparada:~# xen-create-image --hostname=xen1.saulparada.com --size=4Gb --swap=256Mb --ip=192.168.72.130 --memory=128Mb --arch=i386 --role=udev General Information -------------------- Hostname : xen1.saulparada.com Distribution : etch Partitions : swap 256Mb (swap) / 4Gb (ext3) Image type : sparse Memory size : 128Mb Kernel path : /boot/vmlinuz-2.6.18.8-xen Initrd path : /boot/initrd.img-2.6.18.8-xen Networking Information ---------------------- IP Address 1 : 192.168.72.130 [MAC: 00:16:3E:C5:E9:B6] Netmask : 255.255.255.0 Broadcast : 192.168.72.255 Gateway : 192.168.72.1 WARNING ------- Loopback module not loaded and you're using loopback images Run the following to load the module: modprobe loop loop_max=255 Creating partition image: /home/xen/domains/xen1.saulparada.com/swap.img Done Creating swap on /home/xen/domains/xen1.saulparada.com/swap.img Done Creating partition image: /home/xen/domains/xen1.saulparada.com/disk.img Done Creating ext3 filesystem on /home/xen/domains/xen1.saulparada.com/disk.img Done Installation method: debootstrap Done Running hooks Done

Page 6: Virtualization With XEN on Debian 5.0.1 Installation and Configuration Tutorial

saulparada 6

Role: udev File: /etc/xen-tools/role.d/udev Role script completed. Creating Xen configuration file Done Setting up root password Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully All done Logfile produced at: /var/log/xen-tools/xen1.saulparada.com.log

There should now be a xen1.saulparada.com configuration file in "/etc/xen/". Open it and add the

line extra = 'xencons=hvc0 console=hvc0' (or extra = 'xencons=xvc0 console=xvc0' if you use serial_device = xvc0 in "/etc/xen-tools/xen-tools.conf") at the end:

# nano /etc/xen/xen1.saulparada.com.cfg

So that the file should looks as follows:

# # Configuration file for the Xen instance xen1.saulparada.com, created # by xen-tools 3.9 on Wed Jun 24 11:25:16 2009. # # # Kernel + memory size # kernel = '/boot/vmlinuz-2.6.18.8-xen' ramdisk = '/boot/initrd.img-2.6.18.8-xen' memory = '128' # # Disk device(s). # root = '/dev/xvda2 ro' disk = [ 'file:/home/xen/domains/xen1.saulparada.com/swap.img,xvda1,w', 'file:/home/xen/domains/xen1.saulparada.com/disk.img,xvda2,w', ] #

Page 7: Virtualization With XEN on Debian 5.0.1 Installation and Configuration Tutorial

saulparada 7

# Hostname # name = 'xen1.saulparada.com' # # Networking # vif = [ 'ip=192.168.72.130,mac=00:16:3E:AD:A7:DD' ] # # Behaviour # on_poweroff = 'destroy' on_reboot = 'restart' on_crash = 'restart' extra = 'xencons=hvc0 console=hvc0' vcpus = '2'

If is not added that line and if we go to the console of the VM using the xm console command, the

boot process seems to hang forever (while in fact, the vm is running perfectly fine and can be connected to it using SSH).

NOTE: if is used a dual-core or quad-core CPU and is wanted the virtual machine to use all CPU

cores, must be added the line vcpus = '2' or vcpus = '4' to the configuration file.

Managing XEN Image-Based Virtual Machines

To start the virtual machine, must be executed the following instruction:

# xm create /etc/xen/xen1.saulparada.com.cfg To log in on that virtual machine execute:

# xm console xen1.saulparada.com NOTE: type CTRL+] if you are at the console, or CTRL+5 if you're using PuTTY to go back to dom0, or

use an SSH client to connect to it (192.168.72.130). To get a list of running virtual machines, type:

# xm list

Page 8: Virtualization With XEN on Debian 5.0.1 Installation and Configuration Tutorial

saulparada 8

The output should look like this:

saulparada:~# xm list Name ID Mem VCPUs State Time(s) Domain-0 0 366 1 r----- 212.7 xen1.saulparada.com 1 128 2 ------ 10.3

To shutdown xen1.saulparada.com, do this:

# xm shutdown xen1.saulparada.com If it is wanted xen1.saulparada.com to start automatically at the next boot of the system, then

perform:

# ln -s /etc/xen/xen1.saulparada.com.cfg /etc/xen/auto Commands Here are the most important XEN commands. Start a virtual machine:

# xm create -c /path/to/config Stop a virtual machine:

# xm shutdown <name> Stop a virtual machine immediately without shutting it down (it is as if is switched off the power

button):

# xm destroy <name> List all running systems:

# xm list Log in on a virtual machine:

# xm console <name> List of all commands:

# xm help

Page 9: Virtualization With XEN on Debian 5.0.1 Installation and Configuration Tutorial

saulparada 9

A list of all virtual machines that were created with the xen-create-image command is available under:

# xen-list-images

saulparada:~# xen-list-images Name: xen1.saulparada.com Memory: 128 IP: 192.168.72.130

Sources:

• http://www.howtoforge.com/virtualization-with-xen-3.3.1-on-debian-etch

• http://www.linuxinstead.com/blog/?p=63