Compile Linux Kernel 2.6.*

Compiling the Linux Kernel will either be the most frustrating or the most coolest thing a linux user have done. Bit it is also something any serious Linux User cannot avoid.

Why Compile a Kernel?

Kernel is the interface to your Hardware, re-compiling/patching the kernel would fix bugs and enhance performance of your hardware.

The How to

Step 1) Getting The Latest Kernel Source Code

The latest kernel source can be downloaded from http://www.kernel.org/
Latest Release till date is 2.6.26
Latest Patch till date is 2.6.27.rc1


Step 2) Extract the downloaded file

#  tar -xvf linux-2.6.26.tar.bz2 -C /usr/src
#  cd /usr/src

Step 3) Configure Kernel

Requirements GCC
$ make menuconfig
(test/menu based configuration tool)
$ make xconfig
(X windows based configuration tool best for KDE)
$ make gconfig
(X windows based configuration tool best for GNOME)
Step4 ) Compile Kernel
$ make (it takes lot of time be patient)
$ make modules
$ su -
# make modules_install

Step 5) Install Kernel

# make install
It will install three files into /boot:
  • System.map-2.6.26
  • config-2.6.26
  • vmlinuz-2.6.26
Step 6 ) Create initrd image

# cd /boot
# mkinitrd -o initrd.img-2.6.26 2.6.26

Step 7) Modify grub (/boot/grub/menu.lst)

title           Kernel 2.6.26 New root           
(hd0,0) kernel        
 /boot/vmlinuz root=/dev/hdb1 ro initrd         
/boot/initrd.img-2.6.26

Step 8) Reboot

# init 6
and you are done if the above steps worked out fine you will have a new Kernel Installed.

1 comment

16
Feb

[...] Patching The Kernel

[...] Patching The Kernel Is Patching a Good Idea? In most of the recent Linux distros available today we find Kernel Version 2.6.9+ which by itself supports all latest devices, but still there might me some improvements done to the installed kernel first option is to download the latest kernel available from http://www.kernel.org which would require a download of 40+Mbs or the other option is to patch your existing kernel. 90-95% of the kernal source remains the same and downloading the entire source for this 5-10% is never a good idea. For this reason, kernel patches are released Kernel patches contain only the files that have changed since the last kernel, hence making it less pain to upgrade. Steps for applying a patch Step 1 ) Take Backup of the existing kernel Source (/usr/src/linux2.6.24 in my case) Step 2 ) Download the patch from http://www.kernel.org remember if you want to upgrade your kernel to 2.6.26 from 2.6.24 you require 2 patches i.e. 2.6.25 and 2.6.26 patching a step by step process, you cant jump. The current stable version of kernel is 2.6.26 & the patch available is 2.6.26.1 Step 3) un-zip the patch file into the kernel sorce directory # tar -xvf patch-2.6.25.tar # tar -xvf patch-2.6.26.tar # mv patch-2.6.* /usr/src/linux2.6.24 Step 4) Change to Source Directory and apply patch # cd /usr/srclinux2.6.24 # patch -p1 < patch-2.6.25 # patch -p1 < patch-2.6.26 for more info on patch command use man patch this command will provide lot of output just have a look at it, patch command uses diff in background and changes approprate parts of the source. After these steps are done you need to recompile the kernal using the same process as discussed in my blog entry Compile Linux Kernel 2.6.* [...]