Home | Download | Documentation | Programming | FAQ | About Me
Configure,Compile and Install Linux Kernel

Initial Setup :

Download the latest stable Linux Kernel from kernel.org , as of now (March-1-2009 ,03:12 AM) the latest stable Kernel version is 2.6.28.7.This article will show how to configure and install new kernel.
Please log in as normal user and download the linux source code compressed file to Desktop from kernel.org and follow the below procedure:
Please don't login as 'root' to perform following activities unless it's required do so. And don't use /usr/src for building kernel.
create a new directory called linux and copy the file into it.

[lg@localhost Desktop]$mkdir linux
[lg@localhost Desktop]$cp linux-2.6.28.7.tar.bz2 linux/
[lg@localhost Desktop]$cd linux
[lg@localhost linux]$ ls
linux-2.6.28.7.tar.bz2

decompress the downloaded linux files by executing following commands

[lg@localhost linux]$ bunzip2 linux-2.6.28.7.tar.bz2
[lg@localhost linux]$ tar -xvf linux-2.6.28.7.tar
[lg@localhost linux]$ ls
linux-2.6.28.7 linux-2.6.28.7.tar

first we use "make" to configuration kernel options and the compile it. To configure kernel options we should create a kernel configuration file called .config.This .config file can be created from scratch or we can use default configuration file supplied by kernel developers or we can use existing .config file from linux distros.

Creating .config file :
creating .config from scratch will take hours- If you have lot of time ,then you can try this option :) so we use the default configuration file supplied by kernel developers. To create the default configuration file provided by kernel developers use following command:

[lg@localhost linux]$ cd linux-2.6.28.7
[lg@localhost linux-2.6.28.7]$ make defconfig

It will the default .config file is created with size of 59KB(this size may vary in your kernel version) as shown below

[lg@localhost linux-2.6.28.7]$ ls -lh .config
-rw-rw-r-- 1 lg lg 59K 2009-02-28 06:29 .config

(If you really interested in creating the configuration file scratch,then use make config instead of above make defconfig )
You can set more configuration options,using make menuconfig ,alternatively you can use gconfig or xconfig for better GUI,which requires GTK+ or QT packages.

[lg@localhost linux-2.6.28.7]$ make menuconfig

Screenshot of menuconfig interface is shown below:



During make config,If you choose "Y" then the configuration option is added directly to kernel image (and your kernel size increases).
If you choose "N" then the configuration option is not added and left out of kernel image.
If you choose "M" it treated as module which can loaded or unloaded whenever required.
After adding few options .config file size is changed.

After adding few options .config file size is changed.

[lg@localhost linux-2.6.28.7]$ ls -l .config
-rw-rw-r-- 1 lg lg 60131 2009-02-28 10:50 .config

Building/Compiling Linux Kernel :
Configuration file is ready, now Build the kernel,

[lg@localhost linux-2.6.28.7]$ make

Above command creates the kernel and now its time to install the new kernel modules,for that you need root access to perform these tasks.

[lg@localhost linux-2.6.28.7]$ su

When we install selected modules,Installing modules using following command will creat new directory named '2.6.28.7' (kernel version) under /lib/modules

[root@localhost linux-2.6.28.7]# make modules_install

[root@localhost linux-2.6.28.7]# ls /lib/modules/
2.6.27.5-117.fc10.i686 2.6.28.7

modules are installed.
Final Steps :
Now we can move main linux kernel image to /boot directory and edit bootloader files. verify the new kernel version ,

[root@localhost linux-2.6.28.7]# make kernelversion
2.6.28.7

copy bzImage and System.map with a suffix above version number for bzImage and System.map file names,

[root@localhost linux-2.6.28.7]# cp arch/i386/boot/bzImage /boot/bzImage-2.6.28.7
[root@localhost linux-2.6.28.7]# cp System.map /boot/System.map-2.6.28.7

Create initial ramdisk for boot process,

[root@localhost linux-2.6.28.7]# mkinitrd /boot/initrd-2.6.28.7.img 2.6.28.7

Finally edit bootloader configuration file /boot/grub/menu.lst

title Fedora-10 (2.6.28.7)
root (hd0,9)
kernel /boot/bzImage-2.6.28.7 ro root=/dev/sda10 rhgb quiet
initrd /boot/initrd-2.6.28.7.img

Reboot the machine and choose the newly installed kernel from bootloader.

[root@localhost linux-2.6.28.7]# reboot


Reference Book :
O'Reilly's "Linux Kernel In A Nutshell - A Desktop Quick Reference" by Greg Kroah-Hartman
Powered by
Open Source Programmers