For the longest time, cloud servers has been limited to the hypervisor’s seeded kernels. They were patched for exploits, and generally worked well – but some people require specific things in their kernel. While you could compile modules before, you were never allowed to touch the kernel itself.

However recently, PV-Grub became available as an option for Cloud Servers. This loads your grub loader and lets you use whatever kernel you feel like. In order to get it, all you need to do is request it in a ticket and give permission to restart the server. However before that, you will need to set up your kernel and a grub stub.

Setting up PV-Grub is a fairly straight forward process, however it is VERY important you triple check your work. Otherwise when the kernel is switched, your server won’t come back up. This article is written for Ubuntu (I tested it on 10.04, I imagine it should work the same on every recent Ubuntu). Since there is some editing of upstart scripts happening, you will need to modify this some for other articles. I’ll be editing the post for other distributions, but I like Ubuntu so it comes first.

All commands are assumed to be ran as root.

First thing we’re going to do is set up our modprobe to make sure that the hardware will work correctly.

# vim /etc/modprobe.d/alias.conf

Then edit the newly created file with this

alias eth0 xennet
alias scsi_hostadapter xenblk

Next we need to make sure that the consoles work in case you need to troubleshoot something. Since Ubuntu uses upstart over init scripts, the files will look like this:

# vim /etc/init/hvc0
start on stopped rc RUNLEVEL=[2345]
stop on runlevel [!2345]

respawn
exec /sbin/getty -8 38400 hvc0

Do the same for xvc0, replacing all instanced of “hvc0” with “xvc0”. Now we need to make sure root can use the consoles –

# vim /etc/securetty

And append hvc0 and xvc0 to this file. Finally, we need to modify our /etc/fstab file for the new block devices.

sed -i "s/sda/xvda/g" /etc/fstab 

Edit: It seems some distributions require it to remain as /dev/sdaX, and others want /dev/xvdaX. Ubuntu 10.04, wants xvda, Ubuntu 10.10 wants sda, I do not have a comprehensive list, so if your server does not boot after the switch, log into rescue more and try to change your fstab back to /dev/sda.

Now that we have the configs out of the way, we need to install the kernel.

# aptitude install linux-image-server

For the dialogs, leave grub-pc blank, and say yes to not installing grub.

Now you’ll want to create a grub stub for the hypervisor to use.

# cd /boot/grub
# ln -s grub.conf menu.lst
# vim grub.conf

Different distributions use grub.conf or menu.lst. Ubuntu uses menu.lst, however I create them both for the sake of not having to remember which distro uses which one. In this file, you will add this. Make sure that you triple check this, make sure there is spaces in the proper places as well.

timeout 5
default 0


title vmlinuz-2.6.32-21-server
        root (hd0)
        kernel /boot/vmlinuz-2.6.32-21-server console=hvc0 root=/dev/xvda1 ro
        initrd /boot/initrd.img-2.6.32-21-server

After this, you’re ready to submit the ticket. After your server comes back up, you can check your kernel with

#uname -a 
Linux pvgrub 2.6.32-21-server #32-Ubuntu SMP Fri Apr 16 09:17:34 UTC 2010 x86_64 GNU/Linux

You now have complete control of your kernel and can rebuild it as you want, even having multiple kernels for different uses, if you so desire.

« »