HostOnNet Blog

How to compile the Linux kernel on Debian or Ubuntu

Looking for Linux Server Admin or WordPress Expert? We can help.

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 to change the default kernel image to load during booting.

About sherly

I am Sherly, living in the city of Alappuzha, which known as the 'Venice of the East'.
Posted in Ubuntu

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.