Deleting the old kernels lost on your hard drive
Spring Cleaning
When you update the kernel, the old version remains on the disk. If you clean up, the reward is several hundred megabytes of free disk space.
All is flux; nothing stays still. This adage also applies to long-term Linux versions such as Ubuntu LTS and CentOS. The most important reasons for regular updates are security and troubleshooting. And the kernel develops, too. Recent patches for Spectre and Meltdown are good examples of important kernel changes that had to arrive through system updates.
But what happens to the old kernel after an update? First of all, the kernel is a normal software package. It is thus managed through the package management system for your Linux variant. In the case of a Debian or Ubuntu system, this means Apt; in the case of Red Hat-based systems, RPM and its friends Yum and DNF.
If you take a closer look, you'll see that there is no update for the kernel package: The package manager simply adds the new version to the system without deleting the previous version. Often several old versions will remain on the disk (see the box "Turning Back the Clock"), which requires a large amount of disk space.
Turning Back the Clock
The Linux kernel is responsible for many tasks, including managing hardware resources, enabling access to individual system components, and providing interfaces for system communication. Various hardware embodiments can sometimes impair this harmonious relationship. In the worst case, the system will not boot after a kernel update. If there are problems after the update, the old kernel might help, at least until the next kernel update. For this reason, most distributions keep one, but more likely several, of the previous kernel packages on disk.
This article shows how to remove old kernel images from your system. The reference systems are Debian 9, Fedora 28, Ubuntu LTS 16.04, and CentOS 7.5. By default, these distributions limit the number of kernel versions installed on the system – at least if they have be installed via a package update. For manually installed versions, or for additional kernel-related packages, the techniques described in this article might not apply (see the box entitled "Kernel-Related Packages").
For the purposes of this article, the term "kernel package" refers to all packages belonging to the kernel, including kernel-related packages. As Figure 1 shows, these packages occupy a significant amount of disk space.
Manual Removal
Handling the software installed on the system is the package manager's task. The basic procedure is similar for all distributions: First, determine the version of the running and working kernel. You need to be sure this current version stays on the system. Then display all kernel packages. The last step is to delete the packages that are no longer required. (Be sure you observe the instructions in the "Caution" box.)
Caution
Problems and data loss can occur when using the package management system. Therefore, make a backup before deleting old kernel versions.
Some distributions even let you delete the current kernel version. Please pay attention to the screen output. Do not delete the last working kernel. Uninstall older kernel versions only if the system is working perfectly.
Use the abstracted commands of the package manager, for example the yum
command instead of rpm
for CentOS. The abstracted commands display an overview before the actions are executed and let you cancel.
Determining the Current Version
The GRUB bootloader usually displays a selection of installed kernel versions at boot time. For Red Hat-based versions, this output is direct; for Debian the list appears in the Advanced Options area (Figure 2); for Ubuntu, you need to press the Shift key to see the list.
The uname -r
command, which is available with all distributions, displays the version of the running kernel. The output for a Debian system is as follows:
$ uname -r 4.9.0-6-rt-amd64
Package Service
Distributions differ in the name and contents of kernel packages. Table 1 gives an overview of the commands you might need to determine the package names, organized by distribution. The commands listed in the table provide the complete names. The names of the packages alone indicate whether they are kernel packages or components.
Table 1
Determining Package Names
Distribution | Command | Examples of Package Names |
---|---|---|
CentOS |
rpm -qa "kernel*" |
kernel-3.10.0-862.9.1, kernel-headers-3.10.0-862.9.1, kernel-devel-3.10.0-862.9.1 |
Fedora |
rpm -qa "kernel*" |
kernel-4.16.3-301, kernel-modules-4.16.3-301, kernel-devel-4.16.3-301 |
Debian |
apt list --installed linux-* |
linux-image-4.9.0-6-amd64, linux-headers-4.9.0-4-amd64 |
Ubuntu LTS |
apt list --installed linux-* |
linux-image-4.15.0-30-generic, linux-headers-4.15.0-30-generic, linux-image-extra-4.15.0-15-generic |
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Fedora Asahi Remix 41 Available for Apple Silicon
If you have an Apple Silicon Mac and you're hoping to install Fedora, you're in luck because the latest release supports the M1 and M2 chips.
-
Systemd Fixes Bug While Facing New Challenger in GNU Shepherd
The systemd developers have fixed a really nasty bug amid the release of the new GNU Shepherd init system.
-
AlmaLinux 10.0 Beta Released
The AlmaLinux OS Foundation has announced the availability of AlmaLinux 10.0 Beta ("Purple Lion") for all supported devices with significant changes.
-
Gnome 47.2 Now Available
Gnome 47.2 is now available for general use but don't expect much in the way of newness, as this is all about improvements and bug fixes.
-
Latest Cinnamon Desktop Releases with a Bold New Look
Just in time for the holidays, the developer of the Cinnamon desktop has shipped a new release to help spice up your eggnog with new features and a new look.
-
Armbian 24.11 Released with Expanded Hardware Support
If you've been waiting for Armbian to support OrangePi 5 Max and Radxa ROCK 5B+, the wait is over.
-
SUSE Renames Several Products for Better Name Recognition
SUSE has been a very powerful player in the European market, but it knows it must branch out to gain serious traction. Will a name change do the trick?
-
ESET Discovers New Linux Malware
WolfsBane is an all-in-one malware that has hit the Linux operating system and includes a dropper, a launcher, and a backdoor.
-
New Linux Kernel Patch Allows Forcing a CPU Mitigation
Even when CPU mitigations can consume precious CPU cycles, it might not be a bad idea to allow users to enable them, even if your machine isn't vulnerable.
-
Red Hat Enterprise Linux 9.5 Released
Notify your friends, loved ones, and colleagues that the latest version of RHEL is available with plenty of enhancements.