How to Compile Linux Kernel on CentOS 7
Last Updated :
24 Mar, 2025
The kernel is the core of a computer's operating system that has complete control over the system and provides basic services for all other parts. The default kernel available in any distribution cannot be customized. We cannot enable or disable any feature on it. Running a custom-compiled Linux Kernel becomes very helpful in cases when the hardware does not support the standard kernel.
Most Linux distributions have a generic pre-built kernel by default, which might not have been specifically optimized for your hardware or use. Compiling a custom Linux kernel lets you enable or disable features, add new modules, optimize the system performance, and resolve compatibility issues—something that is useful for advanced users, programmers, and system administrators.
Here we understand how to compile and install the Linux kernel in Linux systems. From installing dependencies required to kernel configuration and building from source, everything is explained in easy, beginner-friendly language. This guide will also assist in enhancing your knowledge of the Linux kernel architecture.
Kernel Compilation and InstallationÂ
We are currently running the default kernel supplied by the distribution. You can check the kernel version by typing the following command.
uname -r
 Requirements before Kernel Compilation
Step 1: For compiling the kernel first we need to update our software package repositories and install the development tools and the ncurses library. Type the command below to proceed.
yum update -y
yum install -y ncurses-devel make gcc bc bison flex elfutils-libelf-devel openssl-devel grub
Installing Requirements
Requirements InstalledStep 2: Now we have the required packages for kernel compilation. We need to install the latest stable version of the Kernel (v.6.0.9) from the source using the wgetcommand under the  /usr/src/ directory. Type the commands below to start downloading the latest kernel.
cd /usr/src/
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.0.9.tar.xz
Downloading the Stable Kernel VersionStep 3: Now extract the downloaded tarball file and then move to the main Linux repository.
tar -xvf linux-6.0.9.tar.xz
cd linux-6.0.9
After Extracting TarballAfter moving into the main Linux repository we need want to copy our existing kernel configuration into this directory. The configuration file of the current kernel will be inside the boot directory. Type the command below to see the configuration files.
ls -alh /boot/config*
Configuration Files in Boot DirectoryTo see the contents of the kernel configuration file type the following commands.
less /boot/config/-3.10.0-1160.76.1.el7.x86_64
Contents of Kernel Configuration fileStep 4: Now for copying the existing kernel configuration file type the following.
cp -v /boot/config/-3.10.0-1160.76.1.el7.x86_64 .config
Step 5: Now the next step is to configure the options in our kernel before compilation and we can do that by running.
make menuconfig
This will bringup a kernel configuration menu where we can select the options we want to enable or disable on the Linux kernel.
Kernel Configuration MenuNote: Be careful while configuring the option, if you choose any configuration that's not supported by your hardware then you might  run into something called Kernel Panic. An internal fatal error from which the system cannot safely recover.
Step 6: Now once you completed it, choose Exit and then Ok to save the configuration. The .config file is updated for the new kernel.
Kernel Configuration MenuCompiling the KernelÂ
Now the next step is to compile the kernel into an rpmpackage. Type the command below to start the compilation.
make rpm-pkg
Compiling the Kernel into RPM PackageNote : Before starting kernel compilation, make sure your system has more than 25GB of free disk space. To check the disk space type "df -h".
This process can take a while depending on the specification of your server. We can see from the screenshot below that the process is consuming CPU.
System Monitor CentOS7The output screen when the compilation is over will look like this:
Kernel Compiled SuccessfullyOnce the compilation completes, install the compiled Kernel using the yum package manager and then reboot the system.
How to Enable the Compiled Linux Kernel for Boot
After you’ve successfully compiled and installed your custom Linux kernel, the next step is to make sure your system can boot with it. Here's how to do it in a few simple steps:
Step 1: Generate Initramfs for the New Kernel
The initramfs is a temporary file system that your system needs during boot. Run the command below to create it:
sudo update-initramfs -c -k 6.0.9
Step 2: Update the GRUB Bootloader
GRUB is the bootloader that shows up when you start your computer and lets you choose which kernel to boot off of. Update GRUB so it will see the new kernel after you have created the initramfs:
sudo update-grub
Step 3: Reboot and Boot into Your New Kernel
Reboot your system now that GRUB has been updated:
sudo reboot
Conclusion
Compiling the Linux kernel can be rough at first, but once you're familiar with the process and tools used, it's a huge way of fine-tuning and customizing your Linux system. If you need to tweak performance, enable special hardware drivers, or observe how the system boots up and runs—having your own kernel gives you more control and understanding.
By following this article, you now know how to download the newest kernel source, configure it according to your existing setup, compile it, and install it correctly. Just remember: always double-check your configuration, use sufficient disk space, and back up critical files before making system modifications.
Similar Reads
How to Install Cockpit on Linux CentOS 7?
The cockpit is a free, open-source Linux Server Management Tool which provides you the facility to control your server using the mouse on the web-interface. The cockpit can be used to perform any server related task such as start containers, storage administration, and network configuration and much
3 min read
How to Upgrade Linux Kernel on CentOS 7
The kernel is a central component of an operating system that manages the operations of the computer and hardware. It basically manages operations of memory and CPU time. It is a core component of an operating system. Kernel acts as a bridge between applications and data processing performed at the
2 min read
How To Install Git on CentOS 7?
Git is a type of version control system. There are two types of version control systems are present. One is Centralised and another one is distributed. Centralized VCs are less effective in nature. So, Distributed VCs now replaced the Centralised version. Git is an example of a distributed version c
3 min read
How to Install GCC Compiler on Linux?
In this article, we will discuss how to install a GCC compiler on Linux. GCC stands for GNU Compiler Collections which is used to compile mainly C and C++ language. It can also be used to compile Objective C and Objective C++. The GCC is an open-source collection of compilers and libraries. Let's st
2 min read
How To Compile And Run a C/C++ Code In Linux
C Programming Language is mainly developed as a system programming language to write kernels or write an operating system. C++ Programming Language is used to develop games, desktop apps, operating systems, browsers, and so on because of its performance. In this article, we will be compiling and exe
4 min read
How to Create File in Linux
Today, we're going to learn about something really important â how to create files in Linux. It's like creating a fresh piece of digital paper to write or store things. We'll explore different ways to do this using simple commands. Whether you're just starting out or have been using Linux for a bit,
7 min read
How to Compile, Decompile and Run C# Code in Linux?
C# is a modern multi-paradigm programming language developed by Microsoft and released in the year 2000. By multi-paradigm we mean that it includes static typing, strong typing, lexically scoped, imperative, declarative, functional, generic, object-oriented, and component-oriented programming discip
2 min read
How to Install Docker on CentOS?
Quick Preview to Install Docker on CentOS:Installation of Docker on CentOS:Open CentOS Terminal.Execute the command yum update in the Root Menu.Run the command yum install -y yum-utils device-mapper-persistent-data lvm2.Execute the command yum-config-manager --add-repo https://download.docker.com/li
4 min read
How to Install Gnome on Arch Linux
Arch Linux is known for its adaptability and moderation, allowing users to create their Linux operating system for specific needs. It is one of the most popular Linux system configurations, providing a clean and easy-to-use interface. assuming you're an arch Linux user hoping to install gnome, follo
5 min read
How to Create a Swap File on Linux?
Linux Operating System has some different features that are unique and not present in any other major operating system like Windows. The Linux Memory Distribution is one of them. The Memory Space in Linux is designed in such a way that the efficiency of the Memory Management could be the best. The L
4 min read