Deleting the old kernels lost on your hard drive
Making Space
Once you have completed the preparations, you can start removing the packages you no longer need. Thanks to the autocomplete function with the tab key, which also works when entering the package name, and the typical Linux copy-paste function with the middle mouse button, handling the long file names is no problem.
Table 2 shows some commands for deleting kernel packages. As with all active package management activities, you need root privileges on the system to delete kernel packages.
Table 2
Removing Kernel Packages
Distribution | Command | Sample Command | With Wildcard |
---|---|---|---|
CentOS |
yum remove package_name |
yum remove kernel-3.10.0-693.2.2 kernel-devel-3.10.0-693.2.2 |
yum remove "kernel*3.10.0-693*" |
Fedora |
dnf remove package_name |
dnf remove kernel-4.16.16-300 kernel-core-4.16.16-300 |
dnf remove "kernel*4.16.16-300*" |
Debian |
apt purge package_name |
apt purge linux-image-4.9.0-3 |
apt purge linux-*4.9.0-3-rt* |
Ubuntu LTS |
apt purge package_name |
apt purge linux-image-4.9.0-3 |
apt purge linux-*4.9.0-3-rt* |
The fact that the kernel packages within a distribution typically start with a uniform name, and that the commands allow wildcards, means that you can delete all the kernel packages of a version with a shortcut. The last column of the table shows some examples. If necessary, add more packages or wildcards to the call.
The commands shown in Table 2 provide an overview of the subsequent actions. Pay special attention to this output if you are using wildcards, and cancel the action if necessary. All commands let you specify multiple packages. Removing a kernel version also deletes the corresponding entry in the boot menu.
Some distributions draw "logical conclusions" and sometimes delete more packages than specified. For Fedora, deleting the kernel modules or kernel core packages also deletes the kernel (Figure 3).
Some of the distributions have their own tools for handling the kernel packages. The following sections describe a few of those tools.
Fedora and CentOS
By default, Fedora limits the number of installed kernel packages to three; CentOS sets the limit at five. The value of the variable installonly_limit
determines the number. Fedora understands installonly
packages to mean packages that can be updated via the package manager, but the old version is not deleted until this limit is reached.
Fedora sets this installonly_limit
value in /etc/dnf/dnf.conf
; CentOS sets the value in /etc/yum.conf
. If you leave this value at 2
or higher, a fallback kernel always remains on the disk [1]. To edit these files, you need root privileges [2]. Be sure you make a backup copy before you make any changes.
Using the Package-config
tool from the yum-utils
package, CentOS gives you a simple approach to deleting previous kernel packages. The yum-utils
package is installed by typing sudo yum install yum-utils
. The sudo package-cleanup --oldkernels --count=2
command deletes all kernel packages except the last two.
Debian and Friends
The Synaptic program is part of many Debian-based distributions. It is installed by typing sudo apt install synaptic
. Depending on the distribution, the call is either synaptic
or with synaptic-pkexec
. Alternatively, you can launch Synaptic via the application menu.
Here too, it is a good idea to first determine the version of the currently running kernel by typing uname -r
. To quickly access the kernel packages, launch Synaptic and set the Status to Installed in the left part of the window, click to activate the area where the packages are listed, and type linux.
Mark the packages (*image*
, *header*
, etc.) of the old versions and select the entry Mark for complete removal in the context menu (right mouse button, Figure 5). Clicking on Apply starts the de-installation. See the box entitled "Debian Automatic" for additional information.
Debian Automatic
Where software requires further packages as dependencies (e.g., libraries for extended functions), the package manager automatically includes them when installing the application. If you remove the program from the system again, these additional "orphaned" packages often remain on the hard disk without serving any useful purpose.
The package managers on all Debian-based distributions (including Ubuntu or Linux Mint) have a routine with the sudo apt autoremove --purge
that lets you remove this unnecessary ballast from the system. In addition to the orphaned packages, the command also cleans up the kernels (Figure 4). This automatic procedure keeps the current and the second-to-last kernel on the system.
If the routine ignores the obsolete kernels, it may be because they are tagged as "manually installed." The apt-mark showmanual | grep linux-image
command lists the packages (and filters out the kernel packages immediately). If you then change the status by typing apt-mark auto package_name
, the caretaker should now clean up the kernel packages as well.
« Previous 1 2 3 Next »
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
-
AlmaLinux OS Kitten 10 Gives Power Users a Sneak Preview
If you're looking to kick the tires of AlmaLinux's upstream version, the developers have a purrfect solution.
-
Gnome 47.1 Released with a Few Fixes
The latest release of the Gnome desktop is all about fixing a few nagging issues and not about bringing new features into the mix.
-
System76 Unveils an Ampere-Powered Thelio Desktop
If you're looking for a new desktop system for developing autonomous driving and software-defined vehicle solutions. System76 has you covered.
-
VirtualBox 7.1.4 Includes Initial Support for Linux kernel 6.12
The latest version of VirtualBox has arrived and it not only adds initial support for kernel 6.12 but another feature that will make using the virtual machine tool much easier.
-
New Slimbook EVO with Raw AMD Ryzen Power
If you're looking for serious power in a 14" ultrabook that is powered by Linux, Slimbook has just the thing for you.
-
The Gnome Foundation Struggling to Stay Afloat
The foundation behind the Gnome desktop environment is having to go through some serious belt-tightening due to continued financial problems.
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.