How To Upgrade Linux Kernel on CentOS 7 with Easy Steps

Posted on

How To Upgrade Linux Kernel on CentOS 7 with Easy Steps

How To Upgrade Linux Kernel on CentOS 7 with Easy Steps

In this guide on the Orcacore website, we want to teach you How To Upgrade Linux Kernel on CentOS 7. Linux kernel is a free, open-source, monolithic, modular, Unix-like operating system kernel. It is the main component of the Linux operating system (OS) and is the core interface between the computer’s hardware and its processes.

The Linux kernel is used by Linux distributions alongside GNU tools and libraries. This combination is sometimes referred to as GNU/Linux.

To complete this guide, log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on the Initial Server Setup with CentOS 7.

Check the Current Kernel Version on CentOS 7

The first step is to check the version of your kernel. To do this, you can use the following command:

uname -msr

In your output, you will see:

**Output**
Linux 3.10.0-1160.42.2.el7.x86_64 x86_64

Then, use the following command to update your CentOS repository:

sudo yum -y update

Add ELRepo Repository on CentOS 7

To upgrade the Linux Kernel on CentOS 7, you’ll need to install a third-party repository called ElRepo. ElRepo offers the latest kernel version available from kernel.org.

First, import the ElRepo GPG key with the following command:

sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

Then, run the command below to add and install the ElRepo on CentOS 7:

sudo rpm -Uvh https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm

When you are finished, you will get the following output:

Add ELRepo Repository on CentOS 7

List Available Kernels on CentOS 7

At this point, you can check for the available kernels on your server. To do this, run the command below:

yum list available --disablerepo='*' --enablerepo=elrepo-kernel

In your output, you will see:

List Available Kernels on CentOS 7

From your output, look at the right-hand column, and notice a series of letters and numbers (which look something like ‘5.4.217-1.e17.elrepo’). This is the kernel version.

Use these two pieces of information to decide which kernel version you want to install. As you can see, the Linux 6 kernel is the latest mainline release.

Install the Latest Kernel on CentOS 7

To install the latest mainline kernel on CentOS 7, run the command below:

sudo yum --enablerepo=elrepo-kernel install kernel-ml
**Output**
Installed:
  kernel-ml.x86_64 0:6.0.0-1.el7.elrepo

Complete!

To install the latest stable kernel, run the following command:

sudo yum --enablerepo=elrepo-kernel install kernel-lt
**Output**
Installed:
  kernel-lt.x86_64 0:5.4.217-1.el7.elrepo

Complete!

Reboot CentOS 7 and Choose the New Linux Kernel

At this point, you need to reboot your server:

reboot

You’ll be presented with the GRUB or boot menu.

Use the arrow keys to select the Linux kernel you have just installed, then press Enter. Your operating system should boot normally.

Set the Default Kernel Version on CentOS 7

Once you confirm that the new kernel is compatible and working correctly, you’ll want to edit the GRUB boot utility so that, by default, it loads your new kernel.

Navigate to /etc/default/ and open the grub file with your text editor. Or, type the following in the terminal:

sudo vi /etc/default/grub

Once the file opens, look for the line that says GRUB_DEFAULT=X, and change it to GRUB_DEFAULT=0. This line will instruct the boot loader to default to the first kernel on the list, which is the latest.

Save the file, and then type the following command in the terminal to recreate the kernel configuration:

sudo grub2-mkconfig -o /boot/grub2/grub.cfg

Reboot once more:

reboot

Verify that the boot loader is set to load the latest kernel by default. This is a critical step when you upgrade the Linux Kernel on CentOS 7!

Conclusion

At this point, you have learned to Upgrade Linux Kernel to the latest version on CentOS 7. Upgrading the Linux kernel on CentOS 7 improves security, performance, and hardware compatibility. It provides bug fixes, better virtualization, and support for new software. You can upgrade using the ELRepo repository and set the new kernel as the default for better stability. When you upgrade the Linux Kernel on CentOS 7, you should always test the result!

Hope you enjoy it. You may also like these articles:

Set Up Time Synchronization on CentOS 7

How to create and delete users on CentOS 7

Set Java Home PATH on CentOS 7

Disable systemd-resolved on CentOS 7

Alternative Methods to Upgrade Linux Kernel on CentOS 7

While the ELRepo method described above is a common and reliable way to upgrade the Linux kernel on CentOS 7, other approaches exist. Keep in mind that CentOS 7 is an older distribution, and direct kernel upgrades might introduce compatibility issues. These alternative methods involve more manual steps and potentially carry a higher risk of system instability if not executed correctly. Always back up your system before attempting any kernel upgrade.

Here are two alternative methods:

Method 1: Using Kernel From Source (Not Recommended for Production)

This method involves downloading the kernel source code from kernel.org, compiling it, and installing it manually. It offers the most control but is also the most complex and error-prone. This is generally not recommended for production environments unless you have extensive experience with kernel compilation and debugging.

Explanation:

  1. Download the Kernel Source: Obtain the desired kernel version’s source code from kernel.org.
  2. Extract the Source: Unpack the downloaded tarball.
  3. Configure the Kernel: Use make menuconfig or other configuration tools to customize the kernel. A default configuration based on your current kernel can be copied to the new kernel source tree.
  4. Compile the Kernel: Use make to compile the kernel.
  5. Install the Kernel: Use make modules_install and make install to install the kernel and its modules.
  6. Update Bootloader: Manually update the GRUB configuration to include the new kernel entry.

Example (Illustrative – Requires Adaptation to Your System):

# Assumes you've downloaded and extracted the kernel source to /usr/src/kernel
cd /usr/src/kernel

# Copy current config (Use with caution - adapt as needed!)
cp /boot/config-$(uname -r) .config

# Configure (Optional - but highly recommended to review)
make menuconfig

# Compile (This will take a *long* time)
make -j$(nproc)  #Use all cores for faster compilation

# Install Modules
sudo make modules_install

# Install Kernel
sudo make install

# Update GRUB Configuration (This is VERY important and system-specific)
# The following is a simplified example and *will* likely need adjustments.
# It's better to manually add a GRUB entry in /boot/grub2/grub.cfg,
# but be extremely careful doing so!  Improper GRUB configuration can
# render your system unbootable.  Consider using grubby instead.
# Example (HIGHLY UNSAFE - DO NOT RUN DIRECTLY)
# grub2-mkconfig -o /boot/grub2/grub.cfg

#Reboot
sudo reboot

Important Considerations:

  • Dependencies: Ensure you have all necessary development tools installed (gcc, make, etc.).
  • Kernel Configuration: Carefully configure the kernel to support your hardware. A misconfigured kernel might not boot.
  • GRUB Configuration: Incorrect GRUB configuration is the most common reason for boot failures after a manual kernel install. Use caution and double-check your settings.
  • Module Compatibility: Ensure that any kernel modules you rely on (e.g., drivers for network cards, graphics cards) are compatible with the new kernel version. You might need to rebuild them.

Method 2: Using Backports (Less Risky, But Limited Availability)

Some distributions or third-party repositories provide "backports" of newer kernel features to older kernels. This involves patching the existing CentOS 7 kernel with selected features from newer kernels. It’s less risky than compiling a new kernel from scratch but offers limited functionality.

Explanation:

  1. Identify Available Backports: Check if any repositories offer backports for CentOS 7 kernels. This is less common these days as CentOS 7 is nearing its end-of-life.
  2. Install Backported Packages: Install the backported kernel packages using yum.
  3. Reboot: Reboot the system to load the backported kernel.

Example (Illustrative – Requires Finding a Backport Repository):

# This is a placeholder - you'll need to find a real backport repository
# and enable it.  This command WILL NOT WORK without a valid repository.
# sudo yum --enablerepo=centos7-backports install kernel-backports

#Reboot
sudo reboot

Important Considerations:

  • Repository Availability: Finding a reliable repository with backported kernels for CentOS 7 is challenging.
  • Limited Functionality: Backports only provide selected features, not a full kernel upgrade.
  • Compatibility: Ensure that the backported kernel is compatible with your existing system and applications.

Disclaimer:

Both of these alternative methods are more advanced and carry a higher risk of system instability than using the ELRepo repository. Proceed with caution and only if you have a strong understanding of Linux kernel management. Always back up your system before attempting any kernel upgrade. Consider migrating to a newer, supported Linux distribution if you require a more recent kernel. While How To Upgrade Linux Kernel on CentOS 7 is possible using these methods, it’s generally not advisable for production systems.

Choosing the right method for How To Upgrade Linux Kernel on CentOS 7 depends on your needs and technical expertise. The ELRepo method is the simplest and safest, while the other methods offer more control but also carry greater risks.

Leave a Reply

Your email address will not be published. Required fields are marked *