Abstract
This page is a tutorial on how to get a custom kernel running on a XENvz VPS.
Preparations
- Test that you can login through the recovery console to your machine.
Configure grub
Install the boot loader:
emerge grub
Configure the boot loader. When asked where to install the grub files, answer /boot:
Configuring pkg...
* Enter the directory where you want to setup grub:
/boot
* *** IMPORTANT NOTE: you must run grub and install
* the new version's stage1 to your MBR. Until you do,
* stage1 and stage2 will still be the old version, but
* later stages will be the new version, which could
* cause problems such as an unbootable system.
* This means you must use either grub-install or perform
* root/setup manually! For more help, see the handbook:
* http://www.gentoo.org/doc/en/handbook/handbook-amd64.xml?part=1&chap=10#grub-install-auto
* Copying files from /lib/grub, /usr/lib/grub and /usr/share/grub to /boot/grub
* Grub has been installed to /boot successfully.
Configure your kernel
I spent quite a considerable amount of time figuring out which kernel to use. xen-sources actually did not compile for me, but I noticed that gentoo-sources these days brings all the necessary xen devices with it. Thus I compiled a generic kernel with genkernel, only switching the following options on:
- Xen compatible kernel in platform options
- Xen block device in block devices
- Xen network device in network devices
I used this line ot run genkernel (having copied my kernel from /usr/src/linux-2.6.34-gentoo-r6 to $HOME/src/linux-2.6.34-gentoo-r6 before:
genkernel --no-splash --no-install --no-symlink --kerneldir=$HOME/src/linux-2.6.34-gentoo-r6 --logfile=/tmp/genkernel.log \
--oldconfig --no-clean --module-prefix=/home/dirk/Source/linux-2.6.34-gentoo-r6/root --bootloader=grub all
Install your kernel
genkernel will put the the kernel, the symbol table and the initrd into /var/tmp/genkernel/. Copy all of these files onto your VPS into the /boot directory. This will make genkernel also generate modules and install them into the “root” subdirectory of my kernel. These need to be merged into your /lib/ on the VPS and rsync can do this job.
Configure your kernel in grub
Next, we configure grub by editing /boot/grub/grub.conf. You need to append four lines to this file that look like this:
title Kernel 2.6.34-gentoo-r6
root (hd0,0)
kernel /boot/kernel-genkernel-x86_64-2.6.34-gentoo-r6 real_root=/dev/xvda1 root=/dev/ram0
initrd /boot/initramfs-2.6.34-gentoo-r6
The title is pretty much arbitrary and in this particular case it won’t ever make a difference. The root line should be exactly as shown above. The kernel line should contain the full path of the kernel file you copied over and otherwise be unchanged (or at least contain real_root and root). The real_root device /dev/xvda1 is a Xen specific block device that we have enabled in our kernel configuration earlier (needless to say it’d better be ‘Y’, not ‘M’). The initrd line’s first parameter should point to the initramfs file generated by genkernel.
Reconfigure your VPS
At this point now we have to make two changes in the control panel. We have to enable Power user mode and Custom kernel. The former is the imortant one here, because it will turn off editing /etc/fstab for you.
Reconfigure /etc/fstab
Now that we’ve done that, replace the ‘s‘ letters of ‘sda‘ in fstab with ‘xv‘, so that your /etc/fstab looks like this:
# This configuration file is auto-generated.
# WARNING: Do not edit this file unless you enable the power user option
# within our control panel, otherwise your changes will be lost.
# I was born of XenVZ!
proc /proc proc defaults 0 0
devpts /dev/pts devpts defaults 0 1
/dev/xvda2 none swap sw 0 1
/dev/xvda1 / ext3 errors=remount-ro 0 1
That’s it. Now power off your machine with sudo poweroff and power it on again through the control panel. You can watch the boot progress through the recovery console. The neat initrd of Gentoo also gives you quite a few options to fix your system if things go wrong.