Scripting

Optimised Kernel

This page was ripped in entirety from http://ck.kolivas.org/faqs/walkthrough.txt I take no credit. I just posted this here in case I lose the bookmark to that site or that the site changes.

Quick walthrough on manually patching to -ck for beginners.


Preparing:
Download the latest kernel from www.kernel.org

Untar it somewhere (people most often use /usr/src/linux-XXX but that
requires root access to write to). Eg using linux-2.6.12.tar.bz2

cd /usr/src/
tar xjf /path/to/linux-2.6.12.tar.bz2


Patching:
rename it to the kernel you're going to patch it to (this is optional but it
allows you to know which kernel is where). Eg if you are patching up to
2.6.12-ck6:

mv linux-2.6.12 linux-2.6.12-ck6

then download the patch you'll be patching with (in this case
patch-2.6.12-ck6.bz2).

By convention most kernel patches are diffed in a way that requires you to
enter the top directory of the kernel you're patching:

cd linux-2.6.12-ck6

Then patch by uncompressing it (bzcat) and patching it (patch) one go by
piping the output of bzcat to patch like so:

bzcat /path/to/patch-2.6.12-ck6.bz2 | patch -p1


Configuring:
Your kernel source needs configuring and the easiest way for beginners is to
copy an existing configuration that you know works and working from that. Eg
most distributions copy the config file to /boot and you'll find something
like this:

/boot/config-2.6.11-1-686-smp

You can either open this from the kernel configuration menu or copy it to be
used by the update script (recommended):

cp /boot/config-2.6.11-1-686-smp .config

A feature of 2.6 kernels that can be exploited is that the kernel build itself
can include the configuration data in it and the contents read easily if the
following options are enabled in general setup (recommended):

[*] Kernel .config support
[*] Enable access to .config through /proc/config.gz

If these are enabled you can copy the existing config and use that instead:

gunzip -c /proc/config.gz > .config

Now you can do the configuration either by bringing up one of the menu based
configuring tools but this won't show you what new options have appeared from
getting a new kernel so I recommend the oldconfig script:

make oldconfig

This will only prompt you for any new features in the kernel which are usually
easy enough to understand, but generally if you don't know then choosing the
default recommended by the script just by pressing enter will do.


Building:
The 2.6 kernel build process is simple:

make

If you have more than one processor such as with hyperthreading or real
multiprocessor you can speed up the process with parallel builds which the
kernel build does exceptionally well. Replace X below with the number of
cpus you have + 1 (a quirk in the build process requires one extra job).
Higher "job numbers" than what I've recommended are pointless as at most
they can only speed up the build process by less than 1%.

make -jX

If you are already running a -ck kernel, you can use BATCH scheduling to make
the build process virtually unnoticeable by using only spare cpu cycles,
provided you have schedtools installed:

schedtool -B -e make -jX

if not, the next best thing on mainline is to nice the make heavily:

nice -n 19 make -jX

Note that 'nicing' the build process does _not_ slow down how long it takes
to build. It just means that if you do anything else on your machine at the
same time it will take priority cpu away.

Installing:
A lot of distributions support methods for installing custom kernels so if you
desire you can use that method. Otherwise here is a manual summary:

cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.12-ck6
make modules_install
cp .config /boot/config-2.6.12-ck6 (optional)
mkinitrd /boot/initrd-2.6.12-ck6.img 2.6.12-ck6 (only required if you use initrd)

if you have another architecture like x86_64 the first step is instead:

cp arch/x86_64/boot/bzImage /boot/vmlinuz-2.6.12-ck6

Then you have to add the information to your bootloader.

Many distributions have automated tools for installing new custom kernels in
their configuration tools and you can use those. Be wary to never make a new
kernel the only option, as if it doesn't boot you may be in serious trouble.
Also it is not a good idea to make it the default kernel to boot if you have
not booted it at least once before.

Manual bootloader install to be done (hopefully)...


Con Kolivas

Last Modified:
Tue Jan 24 11:30:11 2006