How to compile the Linux kernel on Debian or Ubuntu

Last updated on August 23, 2012 by Dan Nanni

Reasons why you want to build a custom Linux kernel are numerous. For example, you may want to add driver support for devices which are not recognized by the generic kernel shipped with Linux distros. You may want to optimize the kernel for your hardware, tweak performance tuning options, or turn on or off specific kernel options that cannot modified at run time. If you would like to compile the Linux kernel for any of these reasons, follow these instructions on compiling the Linux kernel on Debian or Ubuntu.

First of all, make sure that you have enough space left in the partition where the kernel source will reside. You need at least 10GB available space in the partition. Once you verify that there is enough space, then proceed as the root as follows.

$ sudo apt-get update
$ sudo apt-get install kernel-package libncurses5-dev fakeroot wget bzip2
$ sudo apt-get install build-essential udev
$ sudo apt-get install linux-source-$(uname -r)
$ cd /usr/src
$ sudo tar xvfvj linux-source-xxxxxx.tar.bz2
$ sudo ln -s linux-source-xxxxxxx ./linux
$ cd /usr/src/linux

$ sudo make clean && make mrproper

$ sudo cp /boot/config-`uname -r` ./.config
$ sudo make menuconfig

(modify kernel configurations as you wish)

(or you could just do: $ make oldconfig)

$ sudo make-kpkg clean
$ sudo fakeroot make deb-pkg

The last step build is going to take 30 minutes to 1 hour depending on your system. If the build is successful, it will generate linux-image-xxxxxx.deb in /usr/src. You can install the newly built custom kernel image as follows.

$ sudo dpkg -i /usr/src/linux-image-xxxxx.deb

Finally, update the GRUB configuration file (/boot/grub/grub.cfg) to change the default kernel image to load during booting.

Support Xmodulo

This website is made possible by minimal ads and your gracious donation via PayPal or credit card

Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.

Xmodulo © 2021 ‒ AboutWrite for UsFeed ‒ Powered by DigitalOcean