Debian kernel recompiling


Recompiling a kernel the Debian way

This is the way to compile a custom kernel against an existing debianized kernel package.

This howto was written with Debian testing/unstable in mind at the time of writing.

It should also be adaptable to debian stable by simply changing the actual kernel version numbers to match those available. It also goes without saying, to simply replace the kernel versions listed in this howto with those that are available in your flavour of debian, testing/unstable, etc.

Get the linux kernel source

apt-get install linux-source-2.6.14
cd /usr/src
tar jxvf linux-source-2.6.14.tar.bz2
ln -s linux-source-2.6.14 linux

You will also need the kernel config file from a debian kernel-image package to make life easier when performing the make oldconfig, otherwise you will be prompted with a truckload of questions that most people who haven’t had much kernel compiling experience would not know how to answer.

The debian kernel-image packages have a kernel config that are usually a good guide of what needs to be set in a kernel. When you perform the make menuconfig you can remove unnecessary or additional components.

** Note: there is now a generic package called linux-image-2.6-k7 (apt-cache search linux-image-2.6- and install the architecture suitable for your system whether that be k7, k7-smp, 386, 686 or so on). This package will always depend on the latest 2.6 kernel image available for your specific cpu architecture.


apt-get install linux-image-2.6-k7
cp /boot/config-2.6.14-2-k7 /usr/src/linux/.config
cd linux

Before we go on, we require the packages kernel-package, debhelper and dpkg-dev which can be obtained by the command:

apt-get install kernel-package debhelper dpkg-dev

If you are going to use menuconfig you will be required to install libncurses5-dev by doing: apt-get install libncurses5-dev.

Kernel patches

There are many kernel patches out there. A lot of the more common kernel patches are actually packaged and can be installed by an apt-get install. If you wish to see if the patch you are after has a debian package simply do an apt-cache search kernel-patch and see if its there. The most common kernel patch that I used for the 2.4 kernel tree was the preemptive patch.

This preempt patch however is now included in the 2.6 kernel and is no longer relevant but an example on how to do so is as follows:

apt-get install kernel-patch-preempt-2.4
cd /usr/src/linux
../kernel-patches/all/apply/preempt

The fun begins…

vi Makefile

Set EXTRAVERSION = -YYYYMMDDn

It is a good idea to set EXTRAVERSION = to todays date where n is a daily serial number (or make EXTRAVERSION = any unique value really). This will change the name of the kernel itself to 2.6.14-20060106 and will also change the location of the kernel modules which stops you from accidently overwriting them with another kernel of the same name.

I personally use my initials as well as an indication of the patches, kernel options and versions of my kernel recompile such as -smp-ajw1

make oldconfig
make menuconfig
make-kpkg clean

Tip!

You can significantly speed up the compile time of your kernel by using distcc. You can read the howto on this subject here.

Now lets compile the new kernel!

make-kpkg --initrd --revision=2:hostname.1.0 kernel_image

It is a good idea that you set –revision in the above command to the hostname of the machine you are compiling the kernel for. This only effects the name of the .deb created and not the kernel name. This comes in handy when compiling custom kernels for several different machines so you can quickly determine which .deb package is for what machine when you have them stored together for whatever reason you may have.

The numbers in –revision do not need to change at all. If you are compiling a number of kernels and don’t want the modules to get mixed up, simply increment the EXTRAVERSION= value in /usr/src/Makefile.

If you also want to know how long it takes to compile your kernel, simply add time to the beginning of the command, for example:

time make-kpkg --initrd --revision=2:anubis.1 kernel_image

Once you have finished compiling you will find yourself with a new kernel-image .deb sitting in /usr/src of which you can install with the following command:

dpkg -i /usr/src/linux-image-2.6.14-ajw1_anubis.1.0_i386.deb

Tip!

You can do both the kernel_image and modules_image commands all in one go (modules_image, builds the .deb packages for modules such as nvidia-kernel-source, pcmcia etc. Instrucions on how to actually complete these module installs can be found in other howto documents here). Simply issue a command like the following:

make-kpkg --initrd --revision=2:anubis.1.0 kernel_image modules_image

… and if you want to build PCMCIA deb’s as well

apt-get install pcmcia-source
cd /usr/src
tar zxvf pcmcia-modules.tar.gz
cd linux
make-kpkg modules_image
cd ..
dpkg -i ../pcmcia-*.deb

Go to Top