Compile a Linux kernel from source

I always like to do something in Linux. Although my plan is a bit different. Right now I don’t want to share here until I finish that. But today I share my experience on compile a Linux kernel from source. You can also try it on your PC. But my recommendation would be to try it in virtual box. Install a lightweight Linux distro like lubuntu in the virtual box. I tried it in my Ubuntu 12.04 (my working PC). The main benefit of compiling it by hand is to get better performance by doing some customize while compiling. Okay, let’s start compiling it.

At first, install all required packages..

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

Then, I enter the directory /usr/src and download the latest and stable version of Linux kernel from the Linux Kernel Archives .

cd /usr/src
wget -c http://www.kernel.org/pub/linux/kernel/v3.0/linux-x.x.x.tar.bz2 (you can choose any stable version)

Extract it and go inside of the folder for preparing for kernel modification

tar xvfvj linux-x.x.x.tar.bz2
cd linux-x.x.x
sudo make clean && make mrproper

Now you will have to configure the menuconfig. This is customizing the kernel. Basically, this is the hardest parts of building own version of the Linux kernel which is determining exactly which drivers and configuration options are required for the machine to work it properly. But in case if you don’t know the configuration, then you can keep the default configuration.

make menuconfig

Now, build the kernel

make-kpkg clean
fakeroot make deb-pkg

By the way, I might take several hours. So don’t be worry. Yes, compiling is done. You will get four files as follows in /usr/src…

linux-headers-
linux-image-
linux-libc-dev_
linux-firmware-image_x.x.x.

Now, install the kernel in your PC..

cd /usr/src
dpkg -i /usr/src/linux-headers--xxxxx.deb
dpkg -i /usr/src/linux-image--xxxxx.deb

if successful, then update your grub

sudo update-grub

Restart your PC. You will see new kernel in your boot menu. Happy hacking 🙂

 

Eftakhairul Islam

Hi, I'm Eftakhairul Islam, a passionate Software Engineer, Hacker and Open Source Enthusiast. I enjoy writing about technical things, work in a couple of startup as a technical advisor and in my spare time, I contribute a lot of open source projects.

 

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.

Read previous post:
Deploy your first RoR App at AppFog

                                   In all of...

Close