How to compile a linux kernel under Debian

From Cosmin's Wiki

Jump to: navigation, search

Home > Linux how to's > How to compile a linux kernel under Debian

Each Linux distribution has its own specific tools for building a custom kernel. This article will guide you step by step in compiling a kernel on Debian etch. I will show you how to compile your custom kernel from the latest kernel sources from and build a debian package (.deb) from it. Please note that this article refers only to 2.6 kernels. First login to your Debian Etch system as root and then install the following prerequisites:

apt-get install kernel-package libncurses5 libncurses5-dev fakeroot

Then go to /usr/src

cd /usr/src

Now get the latest Linux kernel source (or the kernel source you want) from


Unpack now the kernel sources:

tar -xzpf linux-2.6.26.tar.gz
cd linux-2.6.26

Usually it is a good idea to take the configuration of your existing (working!) kernel 2.6 as a starting point for the configuration of your new kernel. Usually the current kernel configuration is saved in a file under /boot, in my case /boot/config-2.6.18-6-686.

make menuconfig

This will open a text-based interface where you can select whatever options you want for your custom kernel to contain:




Then run the following commands (please note that make dep is not needed any more for kernel 2.6):

make-kpkg clean
fakeroot make-kpkg --initrd --append-to-version=-cosmin kernel_image kernel_headers

If the compilation stops with an error, run

make clean

and then re-run the previous commands starting with

make menuconfig

Change the kernel configuration where the error occurs. If no error occurs, you will find under /usr/src two .deb packages: linux-image-2.6.26-cosmin_2.6.26-cosmin-10.00.Custom_i386.deb (which contains the actual kernel) and linux-headers-2.6.26-cosmin_2.6.26-cosmin-10.00.Custom_i386.deb (which contains files needed if you want to compile additional kernel modules later on).

Now you can install your new linux like this: If no error occurs you will find the new kernel as a Debian package called linux-image-2.6.26-cosmin_2.6.26-cosmin-10.00.Custom_i386.deb under /usr/src.

dpkg -i linux-image-2.6.26-cosmin_2.6.26-cosmin-10.00.Custom_i386.deb

You can now even transfer the two .deb files to other Debian Etch systems and install them there without having to recompile the kernel again.

Now we're done. The GRUB bootloader configuration file /boot/grub/menu.lst has been modified automatically, and a ramdisk for the new kernel has been create in /boot.

Now reboot the system:

shutdown -r now

and after the system has booted

uname -a