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.

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.
Table of Contents
- Why Should You Remove Old Kernels?
- First: Check Your System’s Kernel Situation
- Step-by-Step: Remove Old Kernels Based on RHEL Version
- For RHEL 8 and RHEL 9
- For RHEL 5, 6, and 7
- For RHEL 3 and 4
- Important Warnings & Best Practices
- Why Not Use rpm Directly for Kernel Removal after RHEL 5?
- Troubleshooting: What If /boot Is Full?
- Recap: Keep Your System Lean and Stable
- Frequently Asked Questions (FAQs)
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): bash
sudo 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?
Yes, it’s safe—as long as you keep at least one or two working kernels (including the one currently in use). Deleting the active kernel or the only backup could leave your system unbootable.
3. How can I check which kernel I’m currently using?
Run the command:
uname -r
This will show the currently running kernel version, which you should not remove.
4. What’s the easiest way to remove old kernels in RHEL?
You can use the built-in dnf or package-cleanup tool. For example:
dnf remove kernel-old-version
Or use:
package-cleanup --oldkernels --count=2
This command will keep the latest 2 kernels and remove the rest.
5. How many kernels should I keep?
It’s recommended to keep at least two kernels:
- A backup in case something goes wrong after updates
- The current one you’re using
6. Will removing old kernels affect GRUB?
Removing old kernels automatically updates GRUB during the removal process. You don’t need to manually update it unless something goes wrong.
7. Can I automate kernel cleanup on RHEL?
Yes. You can create a cron job or use system management tools like dnf-automatic to periodically remove old kernels using package-cleanup.
8. Does this method work on CentOS or Fedora too?
Yes, the process is very similar for CentOS and Fedora, since they are closely related to RHEL. Just make sure you’re using the correct package manager and kernel naming conventions.