Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Upgrading the Linux Kernel on CentOS 7 and CentOS 8

Tech 1

Overview

The default kernel shipped with CentOS 7 and CentOS 8 is often older then what modern applications require. This guide covers two methods for upgrading the Linux kernel: using the ELRepo repository package manager, or manually installing RPM packages.

Warning: Kernel upgrades require careful consideration. The kernel is the core of the operating system, managing process scheduling, memory allocation, device drivers, and system calls.

Understanding Kernel Packages

Several kernel-related packages exist in CentOS:

  • kernel: Core kernel for single-core, multi-core, and multi-processor systems
  • kernel-devel: Headers and makefiles for building kernel modules
  • kernel-headers: C header files for kernel-user space interface
  • kernel-tools: Utilities for kernel manipulation
  • perf: Performance monitoring tools
  • linux-firmware: Device firmware files

Method 1: Using yum/dnf Package Manager

Adding the ELRepo Repository

The ELRepo repository provides newer kernel versions not available in default repositories.

# For CentOS 8
sudo dnf -y install https://www.elrepo.org/elrepo-release-8.el8.elrepo.noarch.rpm

# For CentOS 7
sudo yum -y install https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm

Verifying Repository Installation

cat /etc/yum.repos.d/elrepo.repo

Importing GPG Key

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

Listing Availbale Kernels

Mainline (latest stable) kernels:

dnf --disablerepo="*" --enablerepo="elrepo-kernel" list available | grep kernel-ml

Long-term support (LTS) kernels:

dnf --disablerepo="*" --enablerepo="elrepo-kernel" list available | grep kernel-lt

Installing the New Kernel

# Install mainline kernel
sudo dnf --enablerepo=elrepo-kernel install kernel-ml

# Or install LTS kernel
sudo dnf --enablerepo=elrepo-kernel install kernel-lt

Installing additional kernel development packages:

# For mainline
dnf --allowerasing --enablerepo=elrepo-kernel install kernel-ml-{devel,headers}


# For LTS
dnf --allowerasing --enablerepo=elrepo-kernel install kernel-lt-{devel,headers}

The --allowerasing flag removes conflicting older packages.

Configuring Default Boot Kernel

CentOS 8 Configuration

# List all available kernels
grubby --info=ALL | grep ^kernel

# Check current default kernel
grubby --default-kernel

# Set new default kernel (replace with your version)
grubby --set-default "/boot/vmlinuz-6.10.4-1.el8.elrepo.x86_64"

# Reboot system
reboot

CentOS 7 Configuration

# View boot menu order
awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg

# Set default boot entry (replace N with entry index)
grub2-set-default N

# Example: set first entry as default
grub2-set-default 0

# Reboot system
reboot

# Verify kernel version
uname -r

Method 2: Manual RPM Installation

This method is useful when installing specific older kernel versions not available in ELRepo.

Locating Kernel RPMs

Download archives for CentOS 7 and 8:

Downloading Required Packages

Three packages are required: the main kernel, development headers, and standard headers.

wget https://mirrors.coreix.net/elrepo-archive-archive/kernel/el7/x86_64/RPMS/kernel-lt-5.4.274-1.el7.elrepo.x86_64.rpm
wget https://mirrors.coreix.net/elrepo-archive-archive/kernel/el7/x86_64/RPMS/kernel-lt-devel-5.4.274-1.el7.elrepo.x86_64.rpm
wget https://mirrors.coreix.net/elrepo-archive-archive/kernel/el7/x86_64/RPMS/kernel-lt-headers-5.4.274-1.el7.elrepo.x86_64.rpm

Installing the Packages

sudo rpm -ivh kernel-lt-5.4.274-1.el7.elrepo.x86_64.rpm
sudo rpm -ivh kernel-lt-devel-5.4.274-1.el7.elrepo.x86_64.rpm

Verifying Installation

rpm -qa | grep kernel

Expected output includes entries like:

  • kernel-lt-5.4.274-1.el7.elrepo.x86_64
  • kernel-lt-devel-5.4.274-1.el7.elrepo.x86_64

Setting Boot Configuration

For CentOS 7:

# View available boot entries
awk -F\' '$1=="menuentry " {print $2}' /etc/grub2.cfg

# Set default entry (index starts at 0)
grub2-set-default 0

# Reboot and verify
reboot
uname -r

For CentOS 8:

# View all kernels
grubby --info=ALL | grep ^kernel

# Check current default
grubby --default-kernel

# Set specific kernel as default
grubby --set-default "/boot/vmlinuz-6.10.4-1.el8.elrepo.x86_64"

# Reboot
reboot
Tags: Linuxcentos

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.