Purpose: There are many ways on how to compile a Linux kernel on a Linux operating system. Here is a step-by-step guide on how to compile a custom Linux kernel, the “Debian way”, on  Debian Lenny.

Step 1: Install Debian system

I guess I don’t need to explain this. If you are at a stage where you want to compile your own kernel you probably already know how to install Debian Linux.

Step 2: Download sources

# apt-get install wget bzip2

Download kernel sources either from www.kenel.org by following:
# cd /usr/src
# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.26.tar.bz2
# tar xjf linux-2.6.26.tar.bz2
# ln -s linux-2.6.26 linux
# cd /usr/src/linux

You can down kernel sources from Debian repository using:
# apt-get install linux-source-2.6.26
# cd /usr/src/
# tar -xjvf linux-source-2.6.26.tar.bz2
# ln -s linux-source-2.6.26 linux
# cd /usr/src/linux

Step 3: Setup the Kernel configuration program
You will need to install the following packages on your system for successfully compiling the Linux kernel.

# apt-get install kernel-package fakeroot build-essential libqt3-mt-dev

Note: Here I am assuming that you are going to configure your kernel from a GNOME environment.

Step 4: Get a kernel config file (.confg)
There are two ways to do that:

Method 1: From an existing (usually older) kernel config file.

# cp /boot/config-2.6.24-1-686 /usr/src/linux/.config
# make oldconfig

Method 2: Generate a default config file

# make defconfig

Step 5: Configure the kernel options

# make xconfig

Select or deselect the items that you want or not want respectively.

Step 6: Compile the kernel

Now it’s time to compile all your hard work.

# make-kpkg --initrd --append-to-version=-mycustomkernel kernel_image kernel_headers

or if you know your kernel will boot without initrd then you can give following command:

# make-kpkg --append-to-version=-mycustomkernel kernel_image kernel_headers

or if you do not want to install the kernel headers for out-of-tree kernel module compilation, give the command:

# make-kpkg --initrd --append-to-version=-mycustomkernel kernel_image

and your resulting kernel will be called as 2.6.26-mycustomkernel in a deb package format.

Step 7: Install your kernel
# dpkg -i linux-image-2.6.26-mycustomkernel_2.6.26-mycustomkernel-10.00.Custom_i386.deb

Step 8: Reboot

Finally you can reboot your system and select your new kernel from your boot loader (typically GRUB) menu.

Additional Notes

If you have multiple core machine (like a dual-core), you can almost double up the kernel compilation  speed i.e. in other words reduce your compilation time to almost half.

Happy Compiling!

Be Sociable, Share!