Many of us may be thinking, if already a machine is running with out any problem, then why is there need of compiling a kernel ??? . For them I hope these three points are more than enough to understand the importance of kernel compilation ;):
1. Your machine may be having some hardware for which there is no corresponding hardware module in the distribution CD.
2. The kernel at present in your server may be having some bugs, which would have been solved in a revision of the operating system.
3. You may want to install some new software in your machine which requires a newer version of operating system.
Clear right 😉 .
Let us assume that the present kernel version is 2.6.28.7. This can be obtained from command ‘uname -r‘
———–
$ uname -r
2.6.28.7
———–
A snippet of file ‘/boot/grub/meny.lst’ [or /etc/grub.conf] before any changes are made in the server:
———————————————-
# cat /boot/grub/menu.lst
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/sda1
# initrd /boot/initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS 5.2
root (hd0,0)
kernel /boot/vmlinuz ro root=/dev/sda1
initrd /boot/initrd.img
———————————————-
The following are the steps to compile kernel:
1. Login to the machine [or server] with root privilege.
2. Download the latest kernel version:
For CentOS you can get the latest kernel versions from link ‘http://www.kernel.org/pub/linux/kernel/v2.6/’ [let us assume that we need to set kernel as 2.6.32.26, so download the corresponding tar file] :
$ cd /usr/src
$ wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.32.26.tar.bz2
3. Untar the downloaded file:
$ tar -xjvf linux-2.6.32.26.tar.bz2
4. Change the directory to the untarred folder and do the following in command prompt:
$ cd linux-2.6.32.26
$ make menuconfig — this will poop up a blue screen which lists the kernel modules. Select the needed modules, save and exit.
$ make dep — this command builds the tree of interdependencies in the kernel sources. These dependencies may have been affected by the options you have choosen in the configure step.
$ make clean — purges any unwanted files left from the previous builds of the kernel.
$ make
$ make modules
$ make modules_install
Till now we have compiled kernel and kernel modules. Now it is required to install the kernel itself. Use following command to install kernel:
$ make install
After the above command is executed, the following changes will be depicted in server :
a. Three new files will be created in /boot directory:
——————
* initrd-2.6.32.26.img [is the initrd image corresponding to kernel 2.6.32.26]
* System.map-2.6.32.26
* vmlinuz-2.6.32.26
——————-
b. A new entry corresponding to new kernel will be added in /boot/grub/menu.lst [as shown below]:
———————————————-
# cat /boot/grub/menu.lst
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/sda1
# initrd /boot/initrd-version.img
#boot=/dev/sda
default=1
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32.26)
root (hd0,0)
kernel /boot/vmlinuz-2.6.32.26 ro root=LABEL=/
initrd /boot/initrd-2.6.32.26.img
title CentOS 5.2
root (hd0,0)
kernel /boot/vmlinuz ro root=/dev/sda1
initrd /boot/initrd.img
———————————————-
Now change the value of ‘default’ in /boot/grub/menu.lst to 0, so that the kernel will boot from the new kernel.
Thus the finale /boot/grub/menu.lst will look like:
———————————————-
# cat /boot/grub/menu.lst
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You do not have a /boot partition. This means that
# all kernel and initrd paths are relative to /, eg.
# root (hd0,0)
# kernel /boot/vmlinuz-version ro root=/dev/sda1
# initrd /boot/initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/boot/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32.26)
root (hd0,0)
kernel /boot/vmlinuz-2.6.32.26 ro root=LABEL=/
initrd /boot/initrd-2.6.32.26.img
title CentOS 5.2
root (hd0,0)
kernel /boot/vmlinuz ro root=/dev/sda1
initrd /boot/initrd.img
———————————————-
5. Reboot the machine.
———–
$ shutsown -r now
or
$ reboot
———–
6. When the server pings login to the server and find the kernel version using:
———–
$ uname -r
2.6.32.26
———–
Success !!! 😉 .
–soumi