Installing Xen On CentOS 5.2 (i386)

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Thu, 2008-11-06 18:57. :: CentOS | Xen | Virtualization

Installing Xen On CentOS 5.2 (i386)

Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 10/27/2008

This tutorial provides step-by-step instructions on how to install Xen (version 3.0.3) on a CentOS 5.2 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.2 (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.2 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

Make sure that SELinux is disabled or permissive:

vi /etc/sysconfig/selinux

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
SELINUX=disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted

If you had to modify /etc/sysconfig/selinux, please reboot the system:

reboot

 

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.

Before we can boot the system with the Xen kernel, please check your GRUB bootloader configuration. We open /boot/grub/menu.lst:

vi /boot/grub/menu.lst

The first listed kernel should be the Xen kernel that you've just installed:

[...]
title CentOS (2.6.18-92.1.13.el5xen)
        root (hd0,0)
        kernel /xen.gz-2.6.18-92.1.13.el5
        module /vmlinuz-2.6.18-92.1.13.el5xen ro root=/dev/VolGroup00/LogVol00
        module /initrd-2.6.18-92.1.13.el5xen.img
[...]

Change the value of default to 0 (so that the first kernel (the Xen kernel) will be booted by default):

[...]
default=0
[...]

The complete /boot/grub/menu.lst should look something like this:

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
#          initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-92.1.13.el5xen)
        root (hd0,0)
        kernel /xen.gz-2.6.18-92.1.13.el5
        module /vmlinuz-2.6.18-92.1.13.el5xen ro root=/dev/VolGroup00/LogVol00
        module /initrd-2.6.18-92.1.13.el5xen.img
title CentOS (2.6.18-92.1.1.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-92.1.1.el5 ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-2.6.18-92.1.1.el5.img
title CentOS (2.6.18-92.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-92.el5 ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-2.6.18-92.el5.img

Afterwards, we reboot the system:

reboot

The system should now automatically boot the new Xen kernel. After the system has booted, we can check that by running

uname -r

[root@server1 ~]# uname -r
2.6.18-92.1.13.el5xen
[root@server1 ~]#

So it's really using the new Xen kernel!

We can now run

xm list

to check if Xen has started. It should list Domain-0 (dom0):

[root@server1 ~]# xm list
Name                                      ID Mem(MiB) VCPUs State   Time(s)
Domain-0                                   0      964     1 r-----    134.1
[root@server1 ~]#


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Johan (not registered) on Wed, 2009-01-21 12:03.
I assume the i386 version differs from the 64 bit version I installed. Virtualisation is an installation option, and Xen is automatically installed, so you can turn to the second page of this manual. The text option in virt-install fails (description of this bug can be found on the internet), but with the --vnc option the installation works as described. Use virt-viewer to connect with vnc to the machine.
Submitted by Anonymous (not registered) on Mon, 2009-01-19 15:52.

I stopped reading at:

"Make sure that SELinux is disabled or permissive:"

 How can an admin that always recommends disabling SELinux provide expert knowledge on other *NIX subjects?

Submitted by admin (registered user) on Mon, 2009-01-19 18:26.
Just because the developers of the OS think that something is a good idea, it doesn't mean that you must use it. It was possible to run secure servers before SELinux, you know.
Submitted by Anonymous (not registered) on Wed, 2008-12-03 21:32.
Is this tutorial good to install on Centos 5 64bit?
Submitted by paalfe (not registered) on Thu, 2008-11-27 16:36.

Xen + ConVirt = Exelent.
http://xenman.sourceforge.net

Project ConVirt is an active, open source project concieved with the goal of tackling the administrative and infrastructure management challenges that adoption of virtualization platforms presents to the traditional datacenter. The eponymous tool "ConVirt" is the project's foremost offering. 


ConVirt is an intuitive, graphical management console providing comprehensive life cycle management for Virtual Machines and virtualization infrastructures. ConVirt is built on the firm design philosophy that ease-of-use and sophistication can, and should, co-exist in a single management tool. With its central console paradigm, performance and configuration dashboard, soup-to-nuts Virtual Machine lifecycle management, integrated Virtual Appliance Catalogue, and many more great features, ConVirt is proving an invaluable tool for seasoned administrators as well as those new to virtualization. 

With ConVirt's secure, multi-node capabilities, infrastructure administrators can safely manage their entire environment from a single, centralized console. Most common administrative tasks like starting/stopping/provisioning virtual machines (Guest OS's) typically involve just a few mouse clicks with ConVirt; as do server management operations like scanning OS configurations or acquiescing individual servers for maintainance. Finally, ConVirt's enterprise grade rapid-provisioning and template management capabilities are an invaluable asset to administrators responsible for QA and Test labs everywhere. 

ConVirt is completely free. It is distributed under the GNU General Public License (GPL).

Submitted by Anonymous (not registered) on Wed, 2008-11-12 15:46.

If you don't understand SELinux, don't just disable it.  Google your problem and fix it.

instead of using /vm, use /xen .

Then run this command to have the correct selinux context:

restorecon -R /xen

 

Submitted by LiRo (not registered) on Fri, 2008-11-07 09:33.

Note:

 To get updated the xen-kernel automatically (and booted as default) change in /etc/sysconfig/kernel the variable "defaultkernel" to "kernel-xen" instead of "kernel"....this way after a kernel update your xen kernel will be booted as default...(and not again normal kernel)