- Trending Categories
- Data Structure
- Operating System
- MS Excel
- C Programming
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Delete Old Unused Kernels in CentOS, RHEL and Fedora?
When you install a new kernel, the old ones are not automatically removed. After a few updates, your system could end up with a lot of unused kernels taking up valuable disk space.
This can cause your system to slow down, and even worse, it can prevent important system services from starting properly. In the worst-case scenario, your system may not even be able to boot at all.
Deleting old unused kernels frees up disk space and ensures that your system runs smoothly. It also reduces the risk of security vulnerabilities that may exist in older versions of the kernel that are no longer updated.
Checking the Current Kernel Version
Using the "uname" command to check current kernel version
One of the most straightforward ways to check the current kernel version in CentOS, RHEL and Fedora is to use the 'uname' command. Simply open a terminal and type 'uname -r'.
The output will display the exact version of your currently running kernel. For example, if you are using CentOS 7 and you run 'uname -r', your screen should display something like this −
The first part, '3.10.0', refers to the major version number of this kernel series, while '-1160.el7.x86_64' is a unique identifier for this specific build of this series deployed in CentOS 7.
Explanation of how to interpret the output
Interpreting output from "uname -r" can seem overwhelming if you're not familiar with certain elements of it. The first set of digits (e.g., 3.10.0), which comes before the dash (-), represents three different numbers separated by dots −
Major Version Number: This represents changes that radically impact compatibility across all devices or computer architectures.
Minor Version Number: This indicates feature or performance improvements that do not affect compatibility among systems
Patch Level Number: This shows bug fixes and other minor changes that don't affect features or performance
The text following the dash represents additional information about this specific build of your Linux distribution's kernel, such as when it was built, which distribution it belongs to, architecture information, etc. It's crucial to understand how to interpret "uname -r" output since it determines which commands and techniques you'll need for managing kernels on your system effectively.
Listing Installed Kernels
One of the first steps in deleting old unused kernels in CentOS, RHEL and Fedora is to list all the installed kernels. This can be done using the RPM package manager.
RPM is a powerful tool for managing system packages and software, and it can also be used to list all installed kernels. To do this, open up a terminal window or log into your server via SSH.
Once you’re logged in, type the following command −
rpm -qa kernel
This will display a list of all currently installed kernels on your system. Each kernel version is listed separately along with other information such as the release date, build number and architecture.
Using "rpm" command to list installed kernels
The "rpm" command is one of the most commonly used commands on CentOS, RHEL and Fedora systems for managing software packages. By default, rpm only shows you packages that are currently installed on your system. To see which versions of the Linux kernel are currently installed on your system using rpm, you can use ```rpm``` with ```-qa``` flag followed by ```kernel```.
This will produce output similar to −
kernel-4.18.0-305.el8.x86_64 kernel-4.18.0-240.el8.x86_64 kernel-4.18.0-147.el8.x86_64 ...
Each line represents an individual kernel package that has been installed onto your system at some point in time (including older unused ones). The information provided includes its version number (e.g., "4.18") as well as its release number (e.g., "-305.el8"), platform architecture (e.g., x86_64), and other details depending on how it was built.
Explanation of how to read the output
When you issue the ```rpm -qa kernel``` command, the output might seem a bit confusing at first glance. However, once you understand what each part of the output means, it becomes much easier to interpret.
First, each line lists a specific kernel package and version number that has been installed on your system. Second, the release number (e.g., "-305.el8") indicates which update or patch level of that particular version is installed.
This is important information to track as newer updates often include important security fixes and bug patches. The architecture (e.g., x86_64) tells you whether the kernel is 32-bit or 64-bit and which CPU architecture it was built for.
Understanding how to read this information will be helpful when removing old kernels later in this article. It's also good practice to keep note of current installed kernels versions so you can track any changes or issues that might arise after deleting unused ones later on in your Linux system maintenance routine.
Removing Old Kernels
Explanation of how to remove old kernels using "yum"
After identifying the old and unused kernels, the next step is to remove them using "yum" - a package manager for RPM-based Linux distributions such as CentOS, RHEL, and Fedora. To remove an old kernel using yum, you should start by opening a terminal window and typing −
sudo yum remove kernel-version
Where "kernel-version" is the version number of the kernel you want to delete. For instance, "sudo yum remove kernel-4.18.0-305.el8.x86_64" would delete version 4.18.0-305.el8.x86_64 on a CentOS system.
Command syntax and options
The syntax for removing an old kernel with yum is simple −
sudo yum remove kernel-version
However, there are additional options that can be added to the command to refine its functionality.
Some common options include: ```--allowerasing```: allows unnecessary dependencies to be removed along with the package without confirmation prompt.
```--exclude=kernel*```: exclude all packages starting with "kernel". ```--skip-broken```: ignore any dependencies that would cause errors in removal.
Precautions and warnings before proceeding
Before proceeding with deleting an old unused kernel, it's crucial that you take precautions to avoid breaking your system or losing important data. Firstly, always back up important data before removing any software from your system; this ensures that you have a copy of all your critical files in case something goes wrong during or after uninstallation.
Secondly, ensure that you double-check the version number of each kernel before deleting it because removing an essential component could lead to some applications malfunctioning or even crashing entirely. If you're unsure about which kernel to delete, it's best to leave them alone and seek professional help if necessary.
Examples for CentOS, RHEL and Fedora
The process of removing an old unused kernel using "yum" is similar across CentOS, RHEL, and Fedora. Below are examples of how to remove old kernels on each system −
sudo yum remove kernel-4.18.0-305.el8.x86_64
sudo yum remove kernel-4.18.0-305.el8.x86_64
sudo dnf remove kernel-5.6.6-300.fc32.x86_64
Note that the version numbers will be different on your system; ensure you double-check before proceeding with any command to avoid unintended consequences.
Deleting old unused kernels is essential to maintaining a healthy and efficient system. Over time, as new kernel versions are released, the older ones can take up valuable space on your system and cause issues when it comes to updating or installing new software. By removing these old kernels, you not only free up valuable disk space but also reduce the risk of conflicts or security vulnerabilities that may exist in outdated versions.
Additionally, leaving old kernels on your system can put a strain on your computer's resources and slow down your machine's performance. Removing them will not only lighten the load but also ensure that your system runs smoothly and efficiently.
Kickstart Your Career
Get certified by completing the courseGet Started