LinuxCommandLibrary

eclean-kernel

Remove old kernel versions

TLDR

List all kernel files

$ sudo eclean-kernel [[-l|--list-kernels]]
copy

Remove all kernels except for the two newest ones
$ sudo eclean-kernel [[-n|--num]] 2
copy

Remove all kernels except for the two newest ones and ask before removal
$ sudo eclean-kernel [[-a|--all]] [[-n|--num]] 2
copy

SYNOPSIS

eclean-kernel [options] [count]

PARAMETERS

count
    Specifies the number of latest kernels to keep. If provided without --keep, it acts as a positional argument.

-h, --help
    Displays a help message and exits.

-l, --list
    Lists all installed kernels and indicates which ones would be removed based on the specified count or default.

-d, --dry-run, --pretend
    Performs a trial run without making any actual changes, showing what would be removed.

-r, --remove
    Initiates the actual removal of identified old kernels. This option is required for changes to take effect.

-k N, --keep N
    Explicitly specifies the number 'N' of latest kernels to keep. Overrides the positional 'count' argument.

-v, --verbose
    Outputs more detailed information during execution.

-q, --quiet
    Suppresses most output, showing only critical information.

DESCRIPTION

eclean-kernel is a specialized command-line utility primarily used on Gentoo Linux systems. Its main purpose is to help users manage and safely remove old, unused kernel images and their corresponding module directories from their system. Over time, after multiple kernel updates, various kernel versions can accumulate, consuming significant disk space. This tool intelligently identifies these older kernels, often by comparing their versions, and provides an option to remove them, while ensuring a specified number of the most recent kernels are kept for stability and rollback purposes. It's an essential part of system hygiene for Gentoo users, working alongside the Portage package manager and genkernel.

Users typically run eclean-kernel with a desired number of kernels to keep, for instance, `eclean-kernel 2` to keep the two latest kernels. It's highly recommended to perform a dry-run using the `--dry-run` or `-d` option before actual removal to see what would be purged. After removing kernels, users must manually update their bootloader configuration (e.g., GRUB) to reflect the changes.

CAVEATS

eclean-kernel is a powerful tool that modifies critical system components.

  • Always use the --dry-run (or -d) option first to preview which kernels will be removed before committing to the action.
  • Ensure you keep at least one known working kernel. It's often recommended to keep at least two or three to have a fallback in case the newest kernel has issues.
  • eclean-kernel does not automatically update your bootloader configuration (e.g., GRUB). After removing kernels, you must manually run your bootloader's configuration update command (e.g., `grub-mkconfig -o /boot/grub/grub.cfg`) to prevent boot errors or missing entries.
  • This utility is primarily designed for Gentoo Linux systems and may not be available or function correctly on other distributions.

BOOTLOADER CONFIGURATION UPDATE

After using `eclean-kernel` to remove old kernels, it is imperative to update your bootloader's configuration. For GRUB users, this typically involves running a command like `grub-mkconfig -o /boot/grub/grub.cfg` to regenerate the boot menu and remove entries for the now-deleted kernels. Failing to do so can result in boot errors or display of non-existent kernel options.

GENTOO LINUX SPECIFIC

While the concept of removing old kernels exists across Linux distributions, `eclean-kernel` is a utility specific to Gentoo Linux. Its functionality is tightly integrated with Gentoo's kernel management practices, such as those involving `genkernel` and the structure of `/boot` and `/lib/modules` on a Gentoo system.

HISTORY

eclean-kernel is part of the gentoolkit package (`app-portage/gentoolkit`), a collection of essential tools for Gentoo Linux system administration. It was developed to address the common issue of accumulating old kernel images, which is particularly relevant in Gentoo due to its source-based nature and the frequent kernel compilation process. Its development ties into the broader Gentoo philosophy of giving users fine-grained control over their system while providing helper utilities for common maintenance tasks.

SEE ALSO

Copied to clipboard