Ubuntu – How to install a realtime kernel

12.04compilingkernelpparealtime

I have read a lot of threads with similar questions, but after reading the answers, I am very confused. I have found in them lots of url's with repositories but people discusses about which repositories are made for one or two versions of ubuntu, but I have found nothing about 11.10 version. Is too soon to ask for that? Should I downgrade my ubuntu to have a realtime kernel?

Best Answer

The long term goal of the RT kernel project is to end up having all the RT functionality in the standard kernel, and this is progressing nicely. The RT patch has had irregular releases in the past, and the hacking of kernel.org in August 2011 made the 3.0 version inaccessible for months, but now things are looking good: there's a patch for 3.0, another for 3.2 (coinciding with the kernel versions in Ubuntu 11.10 and 12.04), and another for 3.4, see here.

If you are using Precise, you can use Alessio Bogani's Realtime PPA, who has kindly packaged the vanilla kernel with the RT patch applied and is keeping it in sync with the version numbers in Precise.

If you prefer to build the RT kernel by hand, first install the required software packages:

sudo apt-get install kernel-package fakeroot build-essential libncurses5-dev

Then fetch the vanilla kernel and RT patch (the version numbers are somewhat old, tweak as necessary):

mkdir -p ~/tmp/linux-rt
cd ~/tmp/linux-rt
wget http://www.kernel.org/pub/linux/kernel/v3.x/linux-3.4.tar.bz2
# Alternatively, try http://mirror.be.gbxs.net/pub/linux/kernel/projects/rt/3.4/patch-3.4-rt7.patch.bz2
# if the following is not available:
wget http://www.kernel.org/pub/linux/kernel/projects/rt/3.4/patch-3.4-rt7.patch.bz2
tar xjvf linux-3.4.tar.bz2
cd linux-3.4
patch -p1 < <(bunzip2 -c ../patch-3.4-rt7.patch.bz2)

Then configure the kernel using:

cp /boot/config-$(uname -r) .config && make oldconfig

where you should select "full preemption" (option 5) when prompted, and leave everything else at its default value by pressing enter at every prompt. The config from the -lowlatency kernel might be a better starting point than that of the -generic kernel.

Then build the kernel with:

sed -rie 's/echo "\+"/#echo "\+"/' scripts/setlocalversion
make-kpkg clean
CONCURRENCY_LEVEL=$(getconf _NPROCESSORS_ONLN) fakeroot make-kpkg --initrd --revision=0 kernel_image kernel_headers

And finally install your new kernel with:

sudo dpkg -i ../linux-{headers,image}-3.4.0-rt7_0_*.deb

You should be able to reboot into your RT kernel at this point. If your kernel fails to boot make sure you double-check the boot parameters, and edit them accordingly in your bootloader. For example, ACPI functions may affect your real time system (as stated on rt.wiki.kernel.org). Adding acpi=off may be a solution in such case.

Notice though that the RT patch is incompatible with the Nvidia binary driver (but see the post by user "rt-kernel" below, and this question for a workaround), and that the Ubuntu kernel patches will not be present, so you may have hardware problems that you did not have before. This is true of both the PPA packages and the compiled kernel. You can always boot into your -generic kernel and uninstall the realtime kernel packages if they give you trouble, of course.