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
Embed
Virtualization With XEN on Debian 5.0.1 Installation and Configuration Tutorial
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
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:
# 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
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:
# 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:
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:
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:
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
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', ] #