Linux Administrator

How To Compile Latest Linux Kernel In CentOS

Recently our one reader requested us to write a article on Kernel up-gradation that’s why I think we should share the all steps with our all readers. As we know each distribution has some specific tools to build a custom kernel from the source. This article will provide how to compile kernel on CentOS system.

In this article I will describe how to compile latest Linux kernel in CentOS. Follow the below steps to do this.

Download Latest Kernel Source

Fist you will need to download latest stable kernel from www.kernel.org for example linux-3.9.7.tar.xz. You can find all 3.9 kernels here https://www.kernel.org/pub/linux/kernel/v3.x/ .

# cd /usr/src/
# wget https://www.kernel.org/pub/linux/kernel/v3.x/linux-3.9.7.tar.xz
# tar -xvf linux-3.9.7.tar.xz

Select Appropriate Module

Now choose the appropriate module and run make menuconfig.

# cd linux-3.9.7
# make menuconfig

Note:- Here you will get kernel configuration screen. Navigate and deselect things such as driver etc. you don not need. If you have any doubt just leave the initial option. Save the configuration and exit from the menu.After saving configuration you will get .config file.

Compile The Kernel

Now lets compile the kernel typing below command:

# make

Note :- It time consuming process and will take more then hour’s depending on your hardware.

Copy Modules

Now copy all the modules to in a new directory such as “/lib/modules/3.9.7” and type below command.

# make modules_install

Copy Compiled Files

Now copy the compiled files in a new appropriate locations and type the below command after copied compiled files.

# make install

Remove All Generated Files, Configuration Backup Files

Then remove the all generated files, such configuration files etc. and type below command.

# make mrproper

Configure The GRUB Boot Loader

Now you must configure you GRUB boot loader so that our new kernels gets booted when you restart the system. For example:

# vim /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 have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
#          initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.9-42.0.3.EL)
        root (hd0,0)
        kernel /vmlinuz-2.6.9-42.0.3.EL ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-2.6.9-42.0.3.EL.img
title CentOS-4 i386 (2.6.9-42.EL)
        root (hd0,0)
        kernel /vmlinuz-2.6.9-42.EL ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-2.6.9-42.EL.img

Edit the above config file to boot the with new kernel during restart. Config file look like afterwords:

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
#          initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (3.9.7-default)
        root (hd0,0)
        kernel /vmlinuz-3.9.7-default ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-3.9.7-default.img
title CentOS (2.6.9-42.0.3.EL)
        root (hd0,0)
        kernel /vmlinuz-2.6.9-42.0.3.EL ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-2.6.9-42.0.3.EL.img
title CentOS-4 i386 (2.6.9-42.EL)
        root (hd0,0)
        kernel /vmlinuz-2.6.9-42.EL ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-2.6.9-42.EL.img

Now reboot the system:

# shutdown -r now

If everything goes well, it should come up with the new kernel. You can check if it’s really using your new kernel by running

# uname -r

Thanks:)

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

1 Comment

  • I read with some interest your explanation of how to install/compile a particular kernel version on CENTOS. I have a problem with CENTOS 8. I need kernel release 4.14.87 installed and compiled on my system, in order that it is compatible with my client’s kernel. I then need to compile my driver with that release of kernel, otherwise my driver will not work on the client system. I have installed CENTOS 8 on a new disk and also downloaded linux-4.14.87.tar.gz in readiness. After unzipping the tar onto my system in the normal way, I understand that I use # make configmenu in order to start an app that allows me to compile the new kernel. Tried this without success, because it reports ncurses-devel is not present. So far I have not been able to resolve this. Any help would be much appreciated.

Leave a Comment