Kernel compiling the old-fashion way

2 minute read

kernel


There are several reasons for compiling a kernel. For instance you might be interested in adding support for a new hardware or functionality, or for tuning your system in order to have a reliable service or application. Whatever your reason is, here you are the directions to compile a kernel the old-fashioned way.

Requisites

Due to you are about to compile a kernel, you’ll need some files and compilers. You will also need ncurses to display dialog on a consoles. In Debian you can install all this by typing:

aptitude install build-essential libncurses5-dev

Working directory

It’s common to use the /usr/src/ directory when compiling the kernel, drivers and modules. So, go to the /usr/src/ directory:

cd /usr/src/

Procedure

You’ll need to get the kernel’s sources to compile them. They can be got from your distro’s repositories or from kernel.org directly. In Debian by installing the following package you will get a tar file in the /usr/src/ directory:

aptitude install linux-source-2.6.30

If you want to download it from kernel.org it would be something like this:

wget -c http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.30.tar.bz2

Now unzip the tar file:

tar xfjv linux-source-2.6.30.tar.bz2

If the linux link exists from previous compilations, remove it:

rm linux

Now make a link to the unzipped directory. If you downloaded the sources from Debian it would be:

ln -s linux-source-2.6.30 linux

If you downloaded from kernel.org, you have to type:

ln -s linux-source-2.6.30 linux

Go the the linux directory:

cd linux

If you’ve compiled other kernels it’s a good idea to clean up everything before starting to compile your new kernel:

make mrproper

Now proceed to set your kernel’s options. To do so, you can use make config (an interactive but annoying interface), make menuconfig (based on ncurses) or make xconfig (you’ll need X running).. I suggest to use the second option:

make menuconfig

You will see a window like the one shown above (main post image). There you can choose new features for your kernel, and tell it to compile them as a module or inside the kernel itself. After you have made your selection, choose Exit to write the .config file

At this point you have already set your kernel, in order to compile it type the following:

make

This step can last a while according to what you’ve chosen. Once it has finished (and if there weren’t errors) proceed to install the compiled image and its modules:

make install
make module_install

You have to make a pre-image, know as initramfs, to help out your kernel to load at boot time. To make that pre-image for your kernel, type the following:

mkinitramfs -o /boot/initrd.img-2.6.30 2.6.30

Now edit grub (or whatever bootlaoder you are using) , to boot your compiled kernel. You can do it manually, or if you are in Debian the update-grub command can do it for you automatically:

update-grub

Finally, reboot your computer and choose you new compiled kernel!!

Leave a Comment