Last revision : February 23th, 2007
You want to compile your very own linux kernel ? No ? Well you should ! Here is a simple receipt.
The steps described below work for both Debian and Ubuntu.
So, read carefully.
Note that I use sudo to get root privileges, refer to this tutorial for more info about that.
First install the required packages :
sudo apt-get install fakeroot bzip2 kernel-package libncurses-dev
Were you planning to compile as root ? That's evil, don't do it. Compile as a normal user : for that you have to put yourself in the src group. My username is mastah, so I type :
sudo adduser mastah src
Then you must logout, and log back in.
First you must download the latest kernel. Browse the Linux Kernel FTP server and download the latest kernel, or simply issue that command while you are in your download directory :
The work begins :
tar jxf /path/to/linux-2.6.20.tar.bz2
At this point prepare to apply the latest patch (or the one of your choice). Remember that patches are generally mutually exclusive : you can only apply one patch to the vanilla (generic) kernel. Some notorious kernel patches include : the realtime patches by Ingo Molnar, and of course the CK patches by Con Kolivas.
In this example we are to use the official 220.127.116.11 patch :
mv linux-2.6.20/ linux-18.104.22.168
Note that if we were to apply the CK patch, replacing 22.214.171.124 with 2.6.20-ck1 would do the trick.
Then test that the patch will apply cleanly :
bzcat /path/to/patch-126.96.36.199.bz2 | patch -p1 --dry-run
If everything outputs ok, then you can apply the patch for real :
bzcat /path/to/patch-188.8.131.52.bz2 | patch -p1
Use the configuration of your choice (I generally use Debian's kernel one) :
cp /boot/config-$(uname -r) .config
Then the fun starts.
To enter the kernel configuration utility, type :
Some important points regarding kernel configuration, presented as examples :
Processor type and features ---> Processor family ---> (X) Core 2/newer Xeon...use your specific CPU here.
Processor type and features ---> Timer Frequency ---> (X) 1000 HZ...for a desktop machine, a high timer frequency is often ideal, as it will confer low latency. For a laptop, choosing a lower frequency will save battery power.
Processor type and features ---> Preemption Model ---> (X) Preemptible Kernel (Low-Latency Desktop)...for a desktop machine, you can choose either Volontary Kernel Preemption or Preemptible Kernel. A fully preemptible kernel will have lower throughput, but quicker response time.
Kernel Hacking --->...this refers to kernel debugging and other various options mainly useful to kernel developers : if you don't plan to do some kernel hacking, you can turn off all those features, as they make the kernel bigger (thus slower).
Device Drivers ---> Graphics support ---> < > Support for frame buffer devices...you want boot time to be as short as possible, so why care about a boot splash image or fancy fonts in console ? So unless you need this, you can turn it off.
Device Drivers ---> Virtualization ---> ...a new feature as of Linux kernel 2.6.20. Be sure to also include INTEL or AMD specific module if you are to use KVM. Very useful feature for virtualization machines like QEMU.
The rest is only optional : setting IDE drivers, SATA drivers (if applicable) and main filesystem to Y (building them statically) will allow you to build a kernel without a RAM disk (initrd), thus speeding the boot process. You have to know your specific chipsets names (output of lspci) by which they are referred by the kernel team. Check the kernel documentation for more (in the /path/to/kernel/Documentation directory).
Finally, don't forget to SAVE.
Now clean the source tree :
fakeroot make-kpkg clean
Then build the kernel package :
fakeroot make-kpkg --append-to-version "<-suffix>" --revision "<revision#>" --us --uc --initrd kernel_image kernel_headers
Install the newly built kernel and its headers :
sudo dpkg -i linux-image-184.108.40.206<-suffix>_<revision#>_i386.deb
sudo dpkg -i linux-headers-220.127.116.11<-suffix>_<revision#>_i386.deb
Replace <-suffix> with whatever you want (like -mykernel), and change <revision#> with a number (like the date, 23022007).
Using the --initrd (RAM disk, to preloads some required modules) parameter gives a working kernel with less efforts (you can build your kernel in an entirely modular way, so you don't have to tweak everything).
Everything is ready, you can reboot...
Make sure you boot into your new kernel!
Saturday, December 17, 2005
Last revision : February 23th, 2007