How to Safely Remove Old Kernels from RHEL: Complete Guide

Photo of author
Written by
Photo of author
Verified by
Updated On
— 5 min read

This guide outlines safe methods to remove outdated kernels from RHEL, CentOS, Rocky Linux, and AlmaLinux systems, where accumulated old kernels in the /boot partition waste disk space. It warns that deleting the active or only backup kernel can render a system unbootable, and advises retaining at least two kernels.

It provides steps for RHEL 3 through 9 to remove individual old kernels, auto-purge outdated versions while keeping the running and latest kernel, and set a retained kernel limit. It recommends yum or dnf over direct rpm to avoid accidental removal, and covers GRUB updates and /boot partition troubleshooting.

Remove Old kernels from RHEL

If you’re managing a Red Hat Enterprise Linux (RHEL), CentOS, RockyLinux or AlmaLinux server, you have likely noticed that over time, old kernels accumulate and eat up space—especially in the /boot partition. While it’s tempting to clear them out, deleting the wrong one can render your system unbootable.

In this guide, you’ll learn how to safely remove outdated kernels from RHEL without risking system stability. We’ll walk through practical steps, explain what to watch out for, and offer tips to keep your system clean and running smoothly. Whether you’re freeing up space or maintaining a production server, this guide is built for real-world use.

Why Should You Remove Old Kernels?

Old kernels won’t harm your system, but they do consume valuable disk space (often in /boot), complicate updates, and can make boot management unwieldy. Yet, always leave at least two kernels—the currently running version and a backup—to ensure you can troubleshoot if your latest kernel fails to boot.

First: Check Your System’s Kernel Situation

1. Find Your Current Running Kernel:

uname -r

2. List All Installed Kernels:

rpm -q kernel

NEVER remove the kernel version you’re actively running!

Step-by-Step: Remove Old Kernels Based on RHEL Version

For RHEL 8 and RHEL 9

1. Remove a Specific Old Kernel

Use this if you want to target a single version:

sudo yum remove kernel-core-<version>

Replace <version> with the version number from your list.

[root@MagnetByte ~]# yum remove kernel-core-5.14.0-570.25.1.el9_6.x86_64 kernel-devel-5.14.0-570.25.1.el9_6.x86_64
Dependencies resolved.
=========================================================================================================================
Package Architecture Version Repository Si
=========================================================================================================================
Removing:
kernel-core x86_64 5.14.0-570.25.1.el9_6 @almalinux-baseos 68
kernel-devel x86_64 5.14.0-570.25.1.el9_6 @almalinux-appstream 70
Removing dependent packages:
kernel x86_64 5.14.0-570.25.1.el9_6 @almalinux-baseos 0
kernel-modules x86_64 5.14.0-570.25.1.el9_6 @almalinux-baseos 36
kernel-modules-core x86_64 5.14.0-570.25.1.el9_6 @almalinux-baseos 28

Transaction Summary
=========================================================================================================================
Remove 5 Packages

Freed space: 201 M
Is this ok [y/N]: y
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1
Erasing : kernel-5.14.0-570.25.1.el9_6.x86_64 1
Running scriptlet: kernel-5.14.0-570.25.1.el9_6.x86_64 1
Erasing : kernel-modules-5.14.0-570.25.1.el9_6.x86_64 2
Running scriptlet: kernel-modules-5.14.0-570.25.1.el9_6.x86_64 2
Erasing : kernel-modules-core-5.14.0-570.25.1.el9_6.x86_64 3
Running scriptlet: kernel-core-5.14.0-570.25.1.el9_6.x86_64 4
/usr/sbin/weak-modules: line 1086: cd: /lib/modules/5.14.0-570.25.1.el9_6.x86_64/weak-updates: No such file or directory

Erasing : kernel-core-5.14.0-570.25.1.el9_6.x86_64 4
Running scriptlet: kernel-core-5.14.0-570.25.1.el9_6.x86_64 4
Erasing : kernel-devel-5.14.0-570.25.1.el9_6.x86_64 5
Running scriptlet: kernel-devel-5.14.0-570.25.1.el9_6.x86_64 5
Verifying : kernel-5.14.0-570.25.1.el9_6.x86_64 1
Verifying : kernel-core-5.14.0-570.25.1.el9_6.x86_64 2
Verifying : kernel-devel-5.14.0-570.25.1.el9_6.x86_64 3
Verifying : kernel-modules-5.14.0-570.25.1.el9_6.x86_64 4
Verifying : kernel-modules-core-5.14.0-570.25.1.el9_6.x86_64 5

Removed:
kernel-5.14.0-570.25.1.el9_6.x86_64 kernel-core-5.14.0-570.25.1.el9_6.x86_64
kernel-devel-5.14.0-570.25.1.el9_6.x86_64 kernel-modules-5.14.0-570.25.1.el9_6.x86_64
kernel-modules-core-5.14.0-570.25.1.el9_6.x86_64

Complete!
[root@MagnetByte ~]#

2. Remove All Old Kernels Except the Newest and Running Kernel

sudo yum remove --oldinstallonly

This keeps the latest and currently running kernel, removing others safely.

3. Keep a Specific Number of Kernels

To specify, for example, the three latest kernels:

sudo yum remove $(yum repoquery --installonly --latest-limit=-3 -q)

4. Ensure Future Cleanliness: Set a Default Limit

Edit /etc/dnf/dnf.conf and add:

installonly_limit=3

This ensures only the latest three kernels are retained during future updates.

For RHEL 5, 6, and 7

1. Remove a Specific Old Kernel

sudo yum remove kernel-<version>

2. Automatic Cleanup with package-cleanup

Ensure the yum-utils package is installed:

sudo yum install yum-utils

Then remove all but two (or your desired number) kernels:

sudo package-cleanup --oldkernels --count=2

Change --count to keep more or fewer kernels.

For RHEL 3 and 4

Remove with RPM (Advanced, Use with Caution)

sudo rpm -e kernel-<version>

Important: Only use specific version numbers. Never use wildcards. Removing all kernels will make your system unbootable.

Important Warnings & Best Practices

  • Never remove your currently running kernel. If needed, reboot into another version first.
  • Always keep at least two kernels installed for backup and troubleshooting.
  • After kernel removal, update your bootloader (if needed): bashsudo grub2-mkconfig -o /boot/grub2/grub.cfg
  • Back up critical system data before performing kernel or package removals.

Why Not Use rpm Directly for Kernel Removal after RHEL 5?

The yum and dnf tools include checks and safeguards, helping prevent accidental removal of essential components or the running kernel. Using rpm -e directly is only advised for older systems (RHEL 3/4), and with utmost caution.

Troubleshooting: What If /boot Is Full?

If /boot has zero free space, it may prevent system updates. First, identify and manually remove the oldest unused kernels using the steps above, then try your updates again.

Recap: Keep Your System Lean and Stable

Consistently removing outdated kernels helps keep your RHEL system running smoothly, avoids update headaches, and ensures you always have a known-good kernel on hand for recovery.

Frequently Asked Questions (FAQs)

1. Why should I remove old kernels from RHEL?

Old kernels can take up unnecessary space on your system—especially in the /boot partition. Over time, this can lead to issues when updating or installing new packages. Cleaning up old kernels helps maintain system performance and stability.

2. Is it safe to remove old kernels from RHEL?

3. How can I check which kernel I’m currently using?

4. What’s the easiest way to remove old kernels in RHEL?

5. How many kernels should I keep?

6. Will removing old kernels affect GRUB?

7. Can I automate kernel cleanup on RHEL?

8. Does this method work on CentOS or Fedora too?

Share

About Author

Photo of author
Linux & WordPress Infrastructure Specialist With over 9 years of hands-on experience, Dhananjay works extensively with Linux servers, WordPress performance optimization, hosting environments, and production infrastructure. His tutorials and reviews are tested on real servers, covering Apache/Nginx, MySQL/MariaDB, PHP, cloud hosting, and security hardening. He focuses on practical, reproducible solutions used by developers, sysadmins, and website owners in real-world environments. Content is regularly reviewed and updated based on production testing.

Leave a Comment