Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to Delete Old Unused Kernels in CentOS, RHEL and Fedora?
Kernel management is a crucial system administration task in CentOS, RHEL, and Fedora. When you install kernel updates, the old versions are kept as a safety measure, but over time these can accumulate and consume valuable disk space, potentially causing boot issues or system slowdowns.
Removing old unused kernels frees up disk space, reduces boot menu clutter, and eliminates potential security vulnerabilities in outdated kernel versions. However, it's important to always keep at least one or two recent kernels as backup in case the current kernel encounters issues.
Checking the Current Kernel Version
Before removing any kernels, you need to identify which kernel version is currently running. Use the uname command to check your current kernel ?
uname -r
This displays output similar to ?
3.10.0-1160.el7.x86_64
The kernel version format consists of ?
Major.Minor.Patch (3.10.0) The upstream kernel version
Build number (1160) Distribution-specific build
Distribution tag (el7) Indicates the distribution version
Architecture (x86_64) The processor architecture
Listing Installed Kernels
To view all installed kernel packages on your system, use the RPM package manager ?
rpm -qa kernel
This produces output showing all installed kernels ?
kernel-4.18.0-348.el8.x86_64 kernel-4.18.0-305.el8.x86_64 kernel-4.18.0-240.el8.x86_64
You can also use rpm -qa | grep kernel to see all kernel-related packages including headers and development packages.
Removing Old Kernels
Manual Removal Method
To remove a specific old kernel, use the appropriate package manager for your distribution ?
CentOS/RHEL 7 and earlier ?
sudo yum remove kernel-4.18.0-240.el8.x86_64
CentOS/RHEL 8+ and Fedora ?
sudo dnf remove kernel-4.18.0-240.el8.x86_64
Automated Cleanup
For easier management, you can configure automatic kernel cleanup. On CentOS/RHEL 8+ and Fedora, set the number of kernels to keep ?
sudo dnf install dnf-utils sudo package-cleanup --oldkernels --count=2
To make this permanent, edit /etc/dnf/dnf.conf and add ?
installonly_limit=3
Using YUM/DNF Remove Old Kernels Plugin
On older systems, you can use the package-cleanup tool ?
sudo yum install yum-utils sudo package-cleanup --oldkernels --count=2
Important Precautions
Never remove the currently running kernel Always verify with
uname -rfirstKeep at least 2-3 recent kernels This provides fallback options if issues occur
Test boot after removal Ensure your system can still boot properly
Backup important data Always maintain current backups before kernel operations
Verifying Successful Removal
After removing old kernels, verify the cleanup was successful ?
rpm -qa kernel df -h /boot
Check your bootloader configuration to ensure removed kernels are no longer listed ?
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
Distribution-Specific Examples
| Distribution | Package Manager | Removal Command |
|---|---|---|
| CentOS 7 | YUM | sudo yum remove kernel-[version] |
| RHEL 8+ | DNF | sudo dnf remove kernel-[version] |
| Fedora | DNF | sudo dnf remove kernel-[version] |
Conclusion
Regular kernel cleanup is essential for maintaining system health and freeing up disk space in /boot. Always keep multiple kernel versions for recovery purposes and use automated cleanup tools to streamline the process. Proper kernel management ensures your system remains secure, stable, and efficient.
