In this article I will show you how to compile kernel from kernel.org on Debian based operating systems like Ubuntu. If you talk to any Linux guru he will say that compiling upstream kernel.org is something very complicated and reserved only for advanced users. That just isn't true. Nowadays to compile upstream kernel without excessive modification of default options all you need is some free time, because compilation process could take 30 to 60 minutes or longer depending on your PC characteristics. So lets get down to business...
Before we start we must make sure that we have all prerequisites. Here I've added all dependencies you might need to compile Linux kernel whether you compile stock Ubuntu/Debian kernel or upstream kernel from kernel.org:
sudo apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package libncurses5 libncurses5-dev
Second thing you should do is to go to www.kernel.org and pick your Linux kernel version. In this article I will compile Linux 22.214.171.124 kernel because this is the last Linux kernel version free of 2.6.38 and 2.6.39 kernel power drain bug. So lets grab the Linux kernel 126.96.36.199 source code (you will download source code for your chosen kernel version instead of
wget -c http://www.kernel.org/pub/linux/kernel/v2.6/linux-188.8.131.52.tar.bz2
Next we need to unpack our kernel source and to prepare for configuring kernel by tweaking its default options.
tar -xjvf linux* && cd linux* make clean && make mrproper
Now we need to configure our kernel options. The kernel configuration interface is started using following command:
There is one option you might wish to change, the "Processor family" option that optimizes kernel for specific processor family. For example if you have Core2 based processor you will go to "Processor type and features" -> "Processor family (Generic-x86-64)" and choose "Core 2/newer Xeon" family. You can change other options you like but don't play with it because if you make wrong choice your kernel might not be able to boot your PC.
Next you start compilation process, this might take a while. You can optimize this process for your number of processor cores by adjusting
CONCURRENCY_LEVEL variable. You might also change "core2" from following commands into something that will help you to identify this kernel on the GRUB kernel list. This can be anything you want like "mykernel" or whatever, but usually people choose something that makes sense for the kernel configuration in question. Here are the commands I use on my Intel Pentium Dual Core processor in my desktop configuration:
make-kpkg clean CONCURRENCY_LEVEL=2 fakeroot make-kpkg --initrd --append-to-version=-core2 kernel_image kernel_headers
After compilation process is finished you will get two .deb files as a result. Here are the commands to install those .deb files, update initramfs and update GRUB with all changes taken into consideration:
cd .. && sudo dpkg -i *.deb sudo update-initramfs -c -k all sudo update-grub
One more thing. If you see you Linux kernel complaining about AppArmor problems during boot you can view my article about disabling and removing AppArmor from your Ubuntu based PC:Disable and remove AppArmor on Ubuntu based Linux distributions
That's it. After you reboot your PC you can use
uname-r command to check your running kernel version. At any point if you need to see GRUB menu when your computer starts, and this menu is hidden, you can pres ESC key while your PC is booting to show it. Please feel free to comment if you have something to add or something isn't working as it should. Isn't Linux operating system fantastic?