Pages

Monday 30 September 2013

Compiling a Custom Linux Kernel on RHEL 5/ Centos 5

                                   Why you need to compile a custom Linux Kernel?
                                   ****************************************
The focus of this article, is to build a custom Linux kernel for your server or desktop machine. The kernel will be optimized for the machine's processor, and will contain support only for the drivers and features that are going to be needed. Another reason to compile a kernel is to add support for a feature that is missing from a vendor supplied kernel, or to get a piece of hardware working.

Step 1: Check you Linux distribution and kernel version by using the following command: 

to check Linux distribution
#cat /etc/issue

to check kernel version
#uname -r

Step 2: if you want to know your kernel features and what are the hardware's is initialized by the running kernel:
#dmesg | less

Step 3: Now Download the latest stable kernel source archive, from Internet, visit the following site, 
www.kernel.org, and download the latest stable kernel source archive. 

Step 4: Now copy your Downloaded latest kernel source archive in to /usr/src directory and extract it.
#cp -rvf /Download/linux-2.6.20.tar.gz /usr/src/

Note: linux-2.6.20.tar.gz, this is my latest kernel source archive name.

Now use the following command to extract it.
#cd /usr/src/
#tar -xvjf linux-2.6.20.tar.gz

Step 5: Now Configure the Kernel, so enter the directory where you unpacked the kernel source:
#cd /usr/src/linux-2.6.20/

Note: you can read the README file for more information. 

There are different utilities provided for configuring the kernel, but we will focus on menuconfig which is a menu driven utility that can be used from the command console. It requires that the some library be installed. Something that should be, by default in most distributions. If you are running XFree86 on your machine, you can also use xconfig but in my opinion, it is more confusing and slower to navigate than menuconfig, and it requires some other packages series be installed.

First Install some packages to compile Linux Kernel
#yum install gcc* qt* make* ncurses* -y

#make clean
#make mrproper

#make menuconfig

Note: you can select your options and features, which you want to enable in your new kernel. 

Now Exit from manuconfig and select "Yes" to save your changes.

Note: when you save and exit from manuconfig, it will create a hidden file ".config". it will have           all the options and features, which you select in manuconfig.

Step 6: Now Compile the Linux kernel:
#make

Step 7: Now Compile the kernel modules:
#make modules

Step 8: Now Install the kernel modules: 
#make modules_install

Step 9: Now install the New Kernel 
#make install

Note: The make install command will create the following files in the /boot directory.
1. vmlinuz-2.6.20 – The actual kernel
2. System.map-2.6.20 – The symbols exported by the kernel
3. initrd.img-2.6.20 – initrd image is temporary root file system used during boot process
4. config-2.6.20 – The kernel configuration file

The command “make install” will also update the grub.cfg by default. So we don’t need to                      manually edit the grub.conf file.

Step 10: Now Boot your Linux to a New Kernel so you need to reboot your Machine. 
#reboot

Step 11: Once the system is up, use uname command to verify that the new version of Linux kernel is installed.
#uname -r


If you have ant trouble to follow these step's, you can click on following link to watch the video

https://www.youtube.com/watch?v=KrQ4Ezyldbw

Thank You,                                   Enjoy.......................!!

2 comments:

  1. Awesome steps to compile kernel in RHEL linux......

    ReplyDelete
  2. Thank you Sureshchandra for wonderful post & video.
    How to create rpm of this compiled kernel? So that we can install custom kernel on other system

    ReplyDelete