The Kernel Purge
Ubuntu utilizes a package manager (APT) that regularly downloads and installs updates, including new versions of the Linux kernel. Over time, old kernels accumulate, taking up valuable space on your `/boot` partition. To prevent this partition from filling up entirely, Ubuntu is configured to automatically remove older, unused kernels during routine package upgrades or when the `unattended-upgrades` background service runs. While generally safe, this automatic removal can be disastrous if a new kernel update contains a bug that breaks your specific hardware (like Wi-Fi drivers or graphics cards), as the stable, older kernel you relied on might be quietly deleted, leaving you unable to boot a working system.
Preserving Fallback Kernels
To ensure you always have a known-working fallback and stop Ubuntu from automatically removing old kernels via the `autoremove` process, you must edit the APT configuration files.
Open a terminal window (Ctrl+Alt+T). You need to edit the configuration file that dictates APT’s autoremove behavior. Type sudo nano /etc/apt/apt.conf.d/01autoremove and press Enter (provide your password when prompted). Inside this file, look for the block of text starting with APT::NeverAutoRemove. This list defines critical packages that the system is forbidden from deleting automatically. To protect your kernels, you need to ensure the regular expression matching the kernel image is present or modify the system’s strictness. A safer, more direct method to stop the unattended-upgrades service from cleaning kernels is to edit its specific file: type sudo nano /etc/apt/apt.conf.d/50unattended-upgrades, locate the line Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";, and change “true” to “false”. Save with Ctrl+O, Enter, and exit with Ctrl+X.