Monday, November 29, 2010

Installing New Kernel from source

Hi Guys,

Today, i am going to discuss a very important aspect of the Operating System that is KERNEL. Kernel is the Core of any Operating System which interacts with the Hardware. Linux kernel is updated on a regular basis. Right now the latest kernel stable release is 2.6.36.1. I will be using this kernel only for this short tutorial.

You can download the kernel source files from http://kernel.org

So download a kernel source first according to your choice of version. I will be using stable kernel 2.6.36.1.

Prequisites:
- A ready Linux installed system (ANY LINUX)
- Kernel source tar balls

Steps to go:-

I will be building my kernel in my HOME directory since i am just trying it out.

1) Download Linux source first either from CLI or GUI as you wish. I will be using the CLI utility 'wget':
# wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.36.1.tar.bz2

2) Uncompress the source archive:
# tar jxvf linux-2.6.36.1.tar.bz2

3) cd into the directory linux-2.6.36.1. Now, we need to configure to select the features we want/need:

# make config

or
# make xconfig
(This is QT based X-Configurations)

or
# make menuconfig
(This is ncurses based)

or
# make gconfig
(This is GTK+ based X-Windows Configurations)

or
# make oldconfig
(This is used in case you want the previous kernel build configurations.)

4) Now building the kernel:
# make

NOTE: If you are using an old kernel like 2.4.x , then you need to build dependencies first using 'make dep'.

With the previous step it will have built both kernel (bzimage) and modules.
For Old Kernels like 2.4.x , you need to run 'make bzimage' and 'make modules'.

5) Now, Become root to install modules and kernel. Everything before can be done as a normal user. There is really no need to do above steps as a root user. Actually, root is a very powerful user. So a single mistake can ruin your system completely.

Install modules as:
# make modules_install

Install the new kernel as:
# make install

6) We are done here. But if in case, your new kernel entry doesn't appear in the GRUB MENU. Then, we have one more steps. Almost all linux distros, automatically edits the grub.conf file and makes the new entry for you. But if thats not a case then, you can do as follows to create a new grub entry:

# vim /etc/grub.conf
title Kernel-2.6.36.1
root (hd0,1)     # provide your root partition here
kernel /boot/vmlinuz-2.6.36.1
initrd /boot/initramfs-2.6.36.1.img
:wq
save and exit

7) DONE. Reboot and boot into the new kernel. Have fun......:)


NOTE:
If you're just trying out this procedure, do the unpacking and building in your home directory as discussed above. In a professional environment, though, the source would be stored in /usr/src or /usr/local/src, where compiling would also be done. To allow this, and at the same time avoid becoming root for the entire procedure, create a group "devel" (or whatever) and add yourself to that group. Then change the group owner of /usr/src to the new group and grant write privileges to the group.

That way you can unpack the kernel tarball into /usr/src (or whatever) and configure and build there without doing everything as root. Of course, you'll still need to sudo or become root when you install the new kernel and edit the grub configuration files.

No comments:

Post a Comment