CentOS and Xen have always made a great pair. They’re even better together when you ignore the 3.0.x packages RedHat distributes with RHEL 5.x.

Compiling Xen 3.4.0 on CentOS 5.3

May 21st, 2009
Tags: ,

By default, pretty much every Linux distribution comes filled with tons of crap you don’t want anywhere near any serious server environment. Unfortunately, distributions rarely have the holy grail of administration – ‘Install only the crap I need to maintain security, compile cool stuff, and stop giving me sixteen text-based e-mail clients.’

Since that doesn’t exist, there’s… I won’t even qualify it as the next best thing. More like the lesser of two evils: a completely barebones system. It’s a pain in the ass, but any serious architecture requires building from the ground up after all.

I find myself in this situation and with the need to install Xen 3.4.0 on a CentOS 5.3 x86_64 box. Note that while I’m CPU class specific, if you’re running i386 or some weird hybrid between the two, these instructions may still be useful. Just strip –exclude=*.i?86 from any yum commands.

On with the show:

cd /opt
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
rpm -ivh rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm
yum --exclude=*.i?86 -y install zlib-devel openssl-devel ncurses-devel python-devel
   xorg-x11-proto-devel bridge-utils binutils gcc mercurial gettext dev86 patch
   texinfo

In the above block, we’re opening up access to the rpmforge third-party repository. Yes – ouch. Don’t worry. rpmforge is ancient, stable and kick ass. Plus I’m lazy and would rather install mercurial, the package we need, via rpm instead of by hand. We’re also installing a number of other packages that we’ll need. Depending on how bare-bones crazy you are, some of these packages might already be installed – but this is the list of ‘oh crap, my system doesn’t even have gcc!’ requirements.

cd /opt
wget http://bits.xensource.com/oss-xen/release/3.4.0/xen-3.4.0-xen.tar.gz
tar -zxf xen-3.4.0-xen.tar.gz
cd xen-3.4.0
make world
make install

Stupid easy, amirite? The nice thing about Xen is, if you’re missing a package (which you shouldn’t be), it’ll pretty much give you a good idea of what you need. Protip: Open up a CentOS5 mirror and use your browser to search for exact package names. If you can’t find one, chances are the build scripts are shooting you an actual file/executable name. In that case, try:

yum whatprovides *NAMEOFWHATEVER

That should locate what package contains whatever it is you’re missing.

Now execute the following:

ls /boot

Take careful note of the name of the file named ‘vmlinuz-BUNCHOFNUMBERS-xen’ – you need that bunch of numbers.

cd /lib/modules
depmod
mkinitrd --allow-missing /boot/initrd-2.6.18.8-xen.img 2.6.18.8-xen

You know that bunch of numbers? They’re what you put in place of the ’2.6.18.8′ in the mkinitrd command above. –allow-missing *should* be fine for most systems.

cd /boot
ln -s vmlinuz-2.6.18.8-xen vmlinuz-xen
ln -s initrd-2.6.18.8-xen.img initrd-xen

Again, replace the ’2.6.18.8′ with the numbers you retrieved via the ‘ls’ command.

Now open up /boot/grub/grub.conf in your favorite text editor. Add the following as the first block of bootable goodness:

title XEN (Xen Virtualization)
        root (hd0,0)
        kernel /xen.gz
        module /vmlinuz-xen ro root=LABEL=/1
        module /initrd-xen

You can pretty much put anything for the title – standards say to put the kernel version, but I don’t like touching grub.conf, which would have to be done in order to continually update the version each time you update your kernel. Fie on that. Thus the reason for the vmlinuz-xen and initrd-xen symlinks; if/when you upgrade, you need only re-point the symlinks rather than messing with grub.conf.

On that note, if you end up yum updating and it replaces your kernel, that *will* edit grub.conf in my experience. So make it a habit to check your grub.conf to make sure your default remains set at 0 after any yum update that plays with the now unused stock kernels.

chkconfig --level=2345 xend on
chkconfig --level=2345 xendomains on

Finally, we set Xen to start on boot.

Reboot, and assuming your system doesn’t crap out (which is beyond the scope of this post), Bob’s yer Uncle Dick.