Saturday, September 4, 2010

Installing Xen On CentOS 5.2 (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.


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
---------------------------

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

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
-------

No comments:

Post a Comment