purge-old-kernels
Remove old, unused Linux kernel versions
SYNOPSIS
purge-old-kernels [OPTIONS]
PARAMETERS
-h, --help
Displays a summary of available command-line options for the script.
-V, --version
Shows the version information for the purge-old-kernels script.
--keep <NUMBER>
Specifies the number of old kernel versions to retain on the system. The default is typically 2, ensuring fallback options.
--purge
Explicitly instructs the script to purge (remove) the identified old kernels. This is usually the default behavior if no other action is specified.
--no-purge
Prevents the script from actually purging kernels. This option is useful when combined with --dry-run to preview actions without making changes.
--dry-run
Simulates the kernel removal process without making any actual changes to the system. It shows which kernels would be removed.
--force
Forces the removal of all old kernels, even if the current kernel is not running. Use with extreme caution as it can lead to an unbootable system.
--verbose
Enables verbose output, displaying more detailed information about the script's operations during execution.
--quiet
Suppresses most of the script's output messages, making it suitable for scripting or automated tasks where minimal output is desired.
--all
Removes all kernel images that are not currently running. Use with caution as it removes all older fallback kernel versions, leaving only the active kernel.
DESCRIPTION
purge-old-kernels is a shell script primarily found in Debian-based Linux distributions (like Ubuntu) designed to automatically remove old, unused kernel images and their associated header packages. As new kernel versions are installed during system updates, older versions are typically retained, allowing users to boot into a previous kernel if the new one causes issues. However, over time, these accumulated old kernels can consume significant disk space. The purge-old-kernels script helps manage this by identifying and removing all but the most recent (and typically one or two fallback) kernel versions, preventing disk space exhaustion and keeping the system tidy. It is often run with superuser privileges and is a crucial utility for system maintenance, especially on systems with limited storage or those undergoing frequent updates. While its functionality has largely been integrated into package managers like apt (e.g., via apt autoremove), the standalone script remains a direct way to perform this specific cleanup.
CAVEATS
Disk Space: While designed to free up disk space, removing too many kernels can leave you without a working fallback option if your current kernel encounters issues.
Boot Issues: Using options like --force or --all can potentially lead to an unbootable system if the latest kernel has problems and all older fallback options are removed.
Distribution Specific: The availability and exact behavior of purge-old-kernels can vary between Linux distributions. In many modern Debian/Ubuntu systems, apt autoremove handles much of this functionality automatically. This specific script is often part of the debian-goodies package.
DEFAULT BEHAVIOR
By default, purge-old-kernels aims to keep the currently running kernel and two previous versions. This provides a balance between disk space conservation and system stability by ensuring readily available fallback boot options.
AUTOMATIC REMOVAL VIA APT
In many modern Debian/Ubuntu setups, old kernels that are no longer referenced by other packages are automatically marked as no longer needed. They can typically be purged simply by running sudo apt autoremove. The purge-old-kernels script offers more explicit and granular control beyond this automatic mechanism.
HISTORY
The purge-old-kernels script has been a long-standing utility within the Debian/Ubuntu ecosystem, designed to address the accumulation of old kernel packages. Its development was driven by the practical need to manage disk space on systems that frequently received kernel updates. While initial versions might have been simpler shell scripts, its functionality was refined and, in many cases, integrated into the apt package management system, particularly with the introduction and widespread use of apt autoremove. Despite this integration, a standalone purge-old-kernels script (often provided by the debian-goodies package) persists, offering a more direct and sometimes more configurable way to perform this specific cleanup task, especially for users who prefer granular control or need to override default behaviors.