The Kernel Cleanup Trap
Ubuntu utilizes a system called “unattended-upgrades” to silently install security patches in the background, including critical Linux kernel updates. To prevent your `/boot` partition from filling up with dozens of obsolete kernels, the `apt` package manager is configured by default to automatically remove older kernel versions, keeping only the current and previous versions available. While this is excellent for storage management on a desktop, it can be a disaster on a production server. If a new kernel update introduces a subtle hardware incompatibility or breaks a proprietary driver, you might need to roll back to a specific older kernel—only to find that Ubuntu automatically deleted it during a routine cleanup.
Protecting Legacy Kernels
To guarantee that you always have access to a specific historical kernel version for rollback purposes, you must stop the package manager from automatically flagging it for removal.
The safest way to protect a specific kernel version is to tell `apt` to place a “hold” on it, preventing it from being modified or removed by automatic cleanup scripts. First, identify the exact version number of the kernel you are currently running (and wish to keep) by opening your terminal and typing uname -r. It will output something like `5.15.0-76-generic`. Next, you must mark all associated packages for that specific version as held. Type the following command, replacing the version number with your specific version: sudo apt-mark hold linux-image-5.15.0-76-generic linux-headers-5.15.0-76-generic linux-modules-5.15.0-76-generic. Press Enter. The system will confirm the packages are on hold. The `apt autoremove` command will now completely ignore these specific kernel files, ensuring they remain safely on your disk indefinitely.