How to remove the old Linux kernel from RHEL8/CentOS8?

Mayank Jain
3 min readJul 8, 2023

--

Hello Folks, in this blog, we will learn how to remove old Linux kernels from RHEL8/CentOS8.

What is Kernel?

The kernel is the main component of a Linux operating system (OS) and is the core interface between a computer’s hardware and its processes. It communicates between the 2, managing resources as efficiently as possible.

The kernel has mainly 4 jobs:

  1. Memory management: Keep track of how much memory is used to store what and where
  2. Process management: Determine which processes can use the central processing unit (CPU), when, and for how long.
  3. Device drivers: Act as mediator/interpreter between the hardware and processes.
  4. System calls and security: Receive requests for service from the processes.

Kernel is working in its own little world known as kernel space, where it allocates memory and keeps track of where everything is stored.

Linux kernel can continue to work during live patching. There’s no downtime while patches are applied for security fixes.

Removing the old Kernel

Login to your Linux machine VM and check the kernel package by running the below command

# rpm -qa kernel | sort -V

From the above output, we are able to see that my Linux machine has 3 kernels present. Now we will check the current kernel which is used by VM by running the below command

# uname -r

Current kernel version

Now we will run the below Linux command to remove the old kernel

# dnf remove kernel-4.18.0–425.3.1.el8.x86_64

The above command will ask for confirmation to remove the kernel, press y and confirm it or you can add an argument in dnf remove command as -y

# dnf remove kernel-4.18.0–425.3.1.el8.x86_64 -y

Note: Make sure you are selecting the correct old kernel version before removing the kernel else your machine will get crash.

We can limit the kernel in Linux by editing the file /etc/yum.conf and setting the installonly_limit variable:

installonly_limit=2

Learn how to set up the Puppet Master and Agent in a virtual box environment here.

Learn RHEL8 custom AMI creation using RHEL Image Builder here.

--

--

Mayank Jain

Skilled DevOps Engineer with 7.5+ years of hands-on experience supporting, automating, & optimizing mission critical deployments in cloud.