AboutMe Linux  Downloads Tools  Pictures Hacker Softwares Games Links Cool  Tricks Tips   Secrets  GuestBook HOME

Linux Kernel Compilation

 Linux Kernel Compilation -A Step By Step Guide

One of the best things that Linux offers to its users is that it gives u the ability to recompile the kernel. But there are some newbies which thinks “why I need this?” or “why should I go for this complex and dangerous procedure?” or “why bother when we install linux and it does everything we need?”The short answer is that today probably u don't need this, but here are couple of situation in which u might need to recompile the kernel. For example some version of Linux are compiled to run on a 386 machine. So if u have P-III then you are unable to take advantage of extended instruction set of P-III. Believe me or not but when the first Mandrake distro came out then it is nothing but a literal copy of the Red Hat Linux which is compile to run on the Pentium (which is perfectly legal under GNU-GPL). But today most of the installations have routines to determine which processor u have and then install the appropriate kernel. But still u need to optimize the kernel, as ur need. For example u might want to optimize the services, networking, SCSI and others according to ur needs or another reason is that u want to stay up to date with the latest kernel realease. So read on.

How kernel is stored, Understanding the basics
When u start the Linux then the first message u see something like

Uncompressing the linux……….
Means the kernel is kept in a compressed file.u might think what is the reason behind it? well The reason behind compressing the kernel is its ability to run on less powered hardware (remember the early 2.5 or 5 gb hardisk???)
The linux kernel stays in the single file, which is vmlinuz. This file is stored in ur /boot directory. It is called vmlinuz rather then linuxkernel or linux .the reason behind this is that the vm is to just to show that linux support virtual memory and the z means it is compressed.
Some distro put the kernel in different then /boot and may or may not be use symbolic links from boot.
To find out where ur kernel stored just open up the /etc/lilo.conf u will see something like this: -

imge =/boot/vmlinuz
label=linux
root=/dev/hda9
So the first line tells that linux expect the kernel to be present in the /boot/vmlinuz or a sumbolic link here.
This one vmlinuz file contains all mostly all the basic things for the linux OS.

Configuring the kernel
Here I assume that u have installed the Linux kernel and put it in to the /usr/src/linux
Now go to this directory (If u don't have this then pls change to proper directory).
Now u need to configure ur Linux kernel for this u can use any of the three options listed bellow: -
1) Configuring through a graphical environment (use make xconfig)
2) Configuring through menu driven environment (use make menuconfig)
3) Configuring through a questionnaire type environment (use makeconfig)

I do not recommend the last option because it is very irritating to answer lots of question in yes/no/default manner.
So u can use the fist option if ur running the xserver or use second option if ur not running xserver.so after this u need to setup the option according to ur need. If u don't know any option then keep that option default.

Compiling the kernel
Ok after u have configured the kernel according to ur need we have to check the dependencies of the configuration, so that we can figure out if something missing. So type

make dep

This will check all the dependencies of the configuration. Suppose if u told the Linux to include A but not include B and if A really needs B then make dep tell u.
After this we have to only make the original kernel so type

make bzImage
Note the capital I. this part of the process will probably take some time as the system builds the new kernel and creates the compressed file. So u can take some coffee.
Now after this look in to the linux source directory. U will see a directory named /arch inside it and another directory named /i386 inside this and then one/boot inside this. In the /boot directory u will see a large file named vmlinuz which is ur newly compiled kernel.

Compiling and linking the modules
The modules means to compile a file with .o extension and store it in the /lib/modules/and when Linux need this then he loads or unload this module according to need. So after the kernel compilation we have to build the module. So type

make modules

Again it will take some time and u can go fro a snack or something. (Infect for many kernel the module contains more code then kernel). After this is done u have to copy the modules in to the /lib/modules/kernel version. The command is make modules_install.
But don't do this now. It is always good to remain on the safe side. So if u run this command before taking backup of existing modules then if u make any mistake during the kernel compilation then u wont be able to boot from old kernel.
So first move the whole /lib/modules to some other place.
Now type

make modules_install

Backing up the old kernel and configuring the file
Ok we r now almost done. First we need to back up our existing kernel if u look into the /boot directory u will find the old kernel image. It is the kernel currently ur booting from. Ok so rename this file such as ur-kernel-name.old
Now copy the new kernel in to /boot directory.
Ok now the second-last step we need to do is to edit the etc/lilo.conf
Now make following changes to ur file: -

imge =/boot/vmlinuz
label=linux
root=/dev/hda9

imge =/boot/vmlinuz.old
label=old-linux
root=/dev/hda9

Label u something see (and possibly type) at the boot prompt and receive when u reboot he system.
And the last step we need is to type

lilo

This will read the /etc/lilo/conf file and configures the boot loader to boot the appropriate images.
Now reboot the system and u see the LILO programs contains two labels that we inserted in the etc/lilo.conf. So press enter to boot from the newly compiled kernel. If every thing works fine then the system boot normally and star using the system.
But if something goes wrong then reboot the system and select the old-kernel. Now if there are some problem with ur new kernel then u have to restart from the make xconfig.

 HOME