On this page

Installing Xen On CentOS 5.0 (i386)

Version 1.0
Author: Falko Timme

This tutorial provides step-by-step instructions on how to install Xen (version 3.0.3) on a CentOS 5.0 system (i386).

Xen lets you create guest operating systems (*nix operating systems like Linux and FreeBSD), so called "virtual machines" or domUs, under a host operating system (dom0). Using Xen you can separate your applications into different virtual machines that are totally independent from each other (e.g. a virtual machine for a mail server, a virtual machine for a high-traffic web site, another virtual machine that serves your customers' web sites, a virtual machine for DNS, etc.), but still use the same hardware. This saves money, and what is even more important, it's more secure. If the virtual machine of your DNS server gets hacked, it has no effect on your other virtual machines. Plus, you can move virtual machines from one Xen server to the next one.

I will use CentOS 5.0 (i386) for both the host OS (dom0) and the guest OS (domU).

This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

1 Preliminary Note

I use the following partitions on my CentOS 5.0 host system (dom0):

/boot 150 MB (ext3)

swap 1GB

/ 3GB (ext3)

/vm the rest (ext3)

I will create the virtual machines in the /vm directory; of course, you can use any other directory that has enough space left, and you don't have to create a partition of its own for it. If you use another directory, replace /vm with your own directory in this tutorial.

If you want to save your virtual machines in /vm, too, but haven't created a partition for it of if the directory /vm doesn't exist on your system, you can create it like this:

mkdir /vm

(Please note: You don't need a /boot partition, but then you have to keep in mind that the Grub stanzas I describe in this howto are slightly different. For example, when I write that I add

2 Installing Xen

To install Xen, we simply run

yum install kernel-xen xen

This installs Xen and a Xen kernel on our CentOS system. Afterwards, we can find our new Xen kernel (vmlinuz-2.6.18-8.1.4.el5xen) and its ramdisk (initrd-2.6.18-8.1.4.el5xen.img) in the /boot directory:

3 Creating A Virtual Machine

CentOS comes with a nice tool called virt-install with which we can create virtual machines for Xen. To start it, we simply run

virt-install

The tools asks a few questions before it creates a virtual machine. I want to call my first virtual machine vm01, with 256MB RAM and a disk size of 4GB. I want to store it in the file /vm/vm01.img:

What is the name of your virtual machine?<-- vm01How much RAM should be allocated (in megabytes)?<-- 256 What would you like to use as the disk (path)?<-- /vm/vm01.imgHow large would you like the disk (/vm/vm01.img) to be (in gigabytes)?<-- 4Would you like to enable graphics support? (yes or no)<-- noWhat is the install location?<-- http://wftp.tu-chemnitz.de/pub/linux/centos/5.0/os/i386

The question about the graphics support refers to the installer, not the virtual machine itself! It is possible to start a graphical installer, but you'd have to connect to it via VNC. It's easier to use the text installer - it offers the same options, so I choose the text installer.

After we have answered all questions, virt-install starts the normal CentOS 5.0 installer (in text mode) in our vm01 virtual machine. You already know the CentOS installer, so it should be no problem for you to finish the CentOS installation in vm01.

After the installation, we stay at the vm01 console. To leave it, type CTRL+] if you are at the console, or CTRL+5 if you're using PuTTY. You will then be back at the dom0 console.

virt-install has created the vm01 configuration file /etc/xen/vm01 for us (in dom0). It should look like this:

What is the install location? <-- http://wftp.tu-chemnitz.de/pub/linux/centos/5.0/os/i386

This fails and all other variations I tried all fail in some way, many begin then error part way through, and I failed to get it to work with the hosts CD rom.

So the answer is to start the http server on the host where you are installing the Virtual Machine, and copy in the packages from the CD_ROM to the root of the http server. In my case this was /var/www/html/ and I created CentOS_5.2_Final/CentOS/ to match the CD-Structure.

The commands are:

$ cd /var/www/html/CentOS_5.2_Final/CentOS

$ cp -r /media/CentOS_5.2_Final/CentOS/ .

And repeat the copy for each of your distro disks.

Then prove it is working by pointing your browser at it, like this:

http://localhost/CentOS_5.2_Final/CentOS/

and you should see all the rpm files you have copied.

Now use http://localhost/CentOS_5.2_Final/CentOS/ as the location and all is well.