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 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- linux/
[lg@localhost Desktop]$cd linux
[lg@localhost linux]$ ls

decompress the downloaded linux files by executing following commands

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

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-
[lg@localhost linux-]$ 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-]$ 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-]$ 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-]$ 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-]$ 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-]$ su

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

[root@localhost linux-]# make modules_install

[root@localhost linux-]# ls /lib/modules/

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-]# make kernelversion

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

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

Create initial ramdisk for boot process,

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

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

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

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

[root@localhost linux-]# reboot

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