Tuesday, February 15, 2011

Compile Linux kernel 2.6

Step # 1 Get Latest Linux kernel code

Visit http://kernel.org/ and download the latest source code. File name would be linux-x.y.z.tar.bz2, where x.y.z is actual version number.

root@asheesh#cd /tmp
root@asheesh#wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-x.y.z.tar.bz2


Step # 2 Extract tar (.tar.bz2) file

root@asheesh# tar -xjvf linux-2.6.25.tar.bz2 -C /usr/src
root@asheesh# cd /usr/src


Step # 3 Configure kernel
root@asheesh# apt-get install gcc (if gcc is not installed)
root@asheesh#make menuconfig

Step # 4 Compile kernel

Start compiling to create a compressed kernel image
root@asheesh# make

Start compiling to kernel modules:
root@asheesh# make modules
root@asheesh#make modules_install

Step # 5 Install kernel

Compiled kernel and installed kernel modules.
root@asheesh#make install

Step # 6: Create an initrd image

Type the following command at a shell prompt:
root@asheesh# cd /boot
root@asheesh# mkinitrd -o initrd.img-2.6.37 2.6.37


Step # 7 Modify Grub configuration file

- /boot/grub/menu.lst (before Edit Please take backup)

Open file using vi or gedit:
root@asheesh# vi /boot/grub/menu.lst

title Debian GNU/Linux, kernel 2.6.25 Default
root (hd0,0)
kernel /boot/vmlinuz root=/dev/hdb1 ro
initrd /boot/initrd.img-2.6.25
savedefault
boot



Remember to setup correct root=/dev/hdXX device. Save and close the file. If you think editing and writing all lines by hand 
is too much for you, try out update-grub command to update the lines for each kernel in /boot/grub/menu.lst file. Just type 

the command:
root@asheesh#update-grub



Step # 8 : Reboot computer and boot into your new kernel

root@asheesh# reboot