Wednesday, August 19, 2009

Compiling Linux Kernel

Note : The following steps were for successful compilation of linux kernel 2.6.30 on the system running with Ubuntu-8.04 with Linux kernel 2.6.24 already present

Step 1:
You will need to install ncurses on your system if it is not already present. It provides a gui interface for the configuration of the kernel.

The latest version can be downloaded from the link :

http://www.gnu.org/software/ncurses/

untar the package and then from the top source directory type the following commands :

$ ./configure –without-cxx-binding
$ make
$ sudo make install


Step 2 :
Download the linux source code for kernel 2.6.30 from the below link :

http://www.kernel.org/pub/linux/kernel/v2.6/

also make sure you have gcc installed on you linux system .




Step 3 :
As root user copy the tar folder in the /usr/src directory and then untar it . For example if you have saved the .tar file on your desktop you can type the following commands current directory being Desktop :

$ sudo bash
~# cp linux-2.6.30.tar.gz /usr/src/
~# cd /usr/src
~# tar -xvvzf linux-2.6.30.tar.gz
~# cd linux-2.6.30




Step 4 :
from the top source directory of linux kernel folder type the following into terminal :
this will open an GUI , form which you can configue the kernel.
You can simply choose the default options by pressing esc two times :

~# make menuconfig



Step 5 :
Now after configure , to compile the kernel run the following command :

~# make

Step 6 :
for compilation for modules :

~# make modules

Step 7:
To install the kernel follow the following :

~# make modules_install
~# make install

Step 8:
Now the bzImage of the kernel is created which is the bunzipped compressed
image. Copy this image to boot directory by the following command :

~# cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.30






Step 9:
To provide the capability to load a RAM disk by the boot loader run the following command form the terminal . At boot time, the kernel unpacks the created archive into a RAM-based disk, which is then mounted and used at the initial root filesystem. Much of the kernel initialization and bootstrap code can then be moved into this disk and run in user mode. Tasks like finding the real root disk, boot-time networking setup, handling of initrd-style ramdisks, ACPI setup, etc. will be shifted out of the kernel in this way.

~# cd /boot
~# mkinitramfs -o initrd.img-2.6.30 2.6.30



Step 10 :
Every thing is done , now update your grub according to the new kernel :
~# update-grub

Step 11 :
To see the changes run the following command :
~# vim /boot/grub/menu.lst


Go down the screen you will find entries which look like following :




As you can see the “Default” and the “recovery mode” does not have the initrd entry, but the third one , the normal kernel entry has it for kernel 2.6.30 , just copy paste the initrd entry from the third configuration and place it at the corrosponding place in the first kernel entry. After which the file will look like following :


for those who are new to vim editor , you can go to insert mode by pressing “i” and then simply copy paste.
To save the changes type the following after pressing “esc” :

~# :wq
You will now come back to the terminal.
That,s it , now simply restart you system. The new kernel entries should show in the Grub menu when you start the system. Select the new kernel that you have installed and start enjoying .

Step 12:
To check wether you are really running the new kernel or not just run the following command from the terminal :
$ cat /proc/version
you will see the deatils of the kernel being run at present.
Like in my system it showed as :

No comments:

Post a Comment

About Me

My photo
Hi Friends, I am Samarth currently pursuing my Masters degree in Information Technology from International Institute of Information Technology ,Bangalore .