Main menu

Compiling and Installing Linux kernel from Source

As you many know, Kernel 4.x.x has been released with tones of changes and enhancements. We all know new kernel always have latest drivers, support for new devices, new features, filesystem enhancements.The feature that all Linux IT guys awaits for, yes it’s Live kernel patching permit a user to update and patch kernel without a reboots. In this article we will Compiling and Installing Linux kernel from Source

Installing Linux kernel from Source

1. Installing dependencies: – Update your system and install dependencies which is required to download, compile and install the Linux kernel

# yum update
# yum groupinstall "Development Tools"
# yum install wget gcc perl ncurses ncurses-devel bc openssl-devel zlib-devel binutils-devel

2. Downloading the Kernel: – Downloading the latest Kernel from and extract it to /usr/src

# wget
# tar -xf linux-4.4.1.tar.xz -C /usr/src/
# cd /usr/src/linux-4.4.1

3. Configure kernel modules: – We have downloaded and extracted the kernel Now it’s time to  configure Linux kernel. All require drivers, features can be configured this way. When we run “make menuconfig” command it will display all available configuration on Kernel. Once we have selected all of the feature wheat we needed to run our system we can save it and it will  generate a .config file with all selected options.

# make menuconfig

If you are not sure about all this, you can run “make oldconfig” you can keep old kernel configuration to to create newer kernel configuration.

# make oldconfig

If you have a GUI installed on your system you can also run “make xconfig” command which is a QT based wizard of menuconfig command

# make xconfig

4. Compiling Kernel Modules: – Now it’s time to build our Kernel modules. make command will build our kernel modules which we have generated on our .config file. During building modules you might get several error about the dependencies. Just install those dependencies and retry.

If you previously build the kernel module cleanup the previous build..

# make clean

make command can take hours, depends on your system configuration. We will create a bzip compressed kernel for i386 and AMD64 architecture.

# make bzImage
# make modules
# make

If you want to distribute your kernel, you can create rpm from your source. After a successful build you can get your kernel on /usr/src/redhat/SRPMS/ directory

# make rpm

There are several options available to make your kernel, you can get help with

# make help

5. Installing Kernel Modules: – Once module compilation is done it’s time to install Linux Kernel on your system. below command will install all new Kernel and modules on your system and also update your Grub to use latest kernel.

# make modules_install install

you may require the initrd image to properly boot your new Linux kernel. You can create initrd for you new linux kernel with mkinitrd command

# mkinitrd -o /boot/initrd.kernel-4.x.x.xdefault.img initrd.kernel-4.x.x.xdefault

If you have build the RPM of your kernel you can install it using rpm command.

# rpm -ivh --nodeps kernel-4.x.x.xdefault.x64.rpm

After installing the latest kernel on your  system run uname command to ensure you are using it.

# uname -r

At the end

It’s Done !! Now you having the latest kernel version but probably you don’t need to compile Latest version of Kernel on your system until have a specific requirement. Sometime it can break your system functionality. If your version having any vulnerability just patch it and  wait for your official repository to release the latest kernel for your Distribution.