DEV Community

Laursen J. Camilla
Laursen J. Camilla

Posted on

How to compile and build Linux kernel 2.6.xx

In this post I want to show you how to compile Linux kernel. I will compile the version 2.6.39.1 which is the latest stable version at the time of writing this post.

I use Debian GNU/Linux, with Linux 2.6.32-5-amd64 with grub2 but generally you can use any distribution to compile it.
Generally compiling and using your own Linux kernel is so easy but if you want to get involved more and want to manipulate some modules! It will be a little hard. But it is so exiting when you work with your own compiled Linux.
Here is the instruction:

  1. Get the latest Linux kernel from Kernel.org I use the version 2.6.39.1 which is the latest stable version at the time of writing this post.

  2. Unzip the archive using the following command.

$ bzip2 -dc linux-2.6.XX.tar.bz2 | tar xvf
Replace your own version with XX in the above command.
There is README file in extracted directory that will help you to customize your compile.

  1. Now call menuconfig function to config and customize kernel to compile. This command will show you a window to select and deselect different modules to compile.

$$ make O=/home/name/build/kernel menuconfig
The O= option determines the target directory to copy built files. If you use this option for this command you should use it for other commands too.

  1. After config, use following command to make kernel. all files will be copied into /home/name/build/kernel

$$ make O=/home/name/build/kernel

  1. Know use this command to install modules.

$$ sudo make O=/home/name/build/kernel modules_install install
This command will copy following files into /boot directory.

Config-2.6.XX
System.map-2.6.XX
Vmlinuz-2.6.XX

  1. Know use following command to make a Ram Disk.

$$ cd /boot
$$ mkinitramfs -o initrd.img-2.6.XX 2.6.XX
Note: some in distributions you should use mkinitrd -o initrd.img-2.6.XX 2.6.XX command to make a ram disk.

  1. Finally if you are using grub2, use following command to update grub and introduce newly compiled kernel to grub. This command will automatically scan /boot directory and update the /boot/grub/grub.cfg. You should just execute the following command.

$$ update-grub2

Note: if you are using grub 1.x use menu.lst to introduce newly complied kernel.
Now reboot your system. You will see a new item with the version of compiled kernel. In grub menu. Just select it and boot your system and enjoy using your own compiled Linux.I have worked for many software developing companies and I was amazed to see that majority of coders and developers does not knew these strings of linux.

Top comments (0)