Compile upstream Linux kernel from on Ubuntu or Debian

Linux kernelIn this article I will show you how to compile kernel from on Debian based operating systems like Ubuntu. If you talk to any Linux guru he will say that compiling upstream 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

sudo apt-get install fakeroot kernel-wedge build-essential makedumpfile kernel-package libncurses5 libncurses5-dev

Second thing you should do is to go to and pick your Linux kernel version. In this article I will compile Linux 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 source code (you will download source code for your chosen kernel version instead of linux- kernel):

wget -c

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:

make menuconfig

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?


A quality focused Magento specialized web development agency. Get in touch!

2 thoughts on “Compile upstream Linux kernel from on Ubuntu or Debian

  1. Jim Wilson

    Thanks for the quick tutorial. I have been searching for an up to date version of this how-to all over the place.
    Maybe add the fact that you should be working in the /usr/src directory during the build process, and do the wget to /usr/src for cleanliness, something like,
    #cd /usr/src
    inserted in there somewhere before your wget command, so that things get proper and clean.
    Thanks for infos!!

  2. Marko Author

    @Jim Wilson

    Hi! I’m glad you found this article useful 😉 About using /usr/src this is Arch Linux wiki article that explains my opinion on this subject.

    But the bottom line is that using /usr/src or home is a mater of debate amongst Linux users, and I my self don’t see any reason for using one vs the other except using home is maybe little simpler for beginners. Cheers!


Leave a Reply

Your email address will not be published. Required fields are marked *