When Ubuntu downloads and installs a new Linux kernel during a routine system update, it does not immediately overwrite your old kernel. It leaves the previous kernel installed as a fallback in case the new one fails to boot. However, to save disk space in the /boot partition, the apt package manager is configured to automatically flag kernels older than the previous version as “orphaned” and will violently purge them the next time an apt autoremove command is triggered.
If you are running specific hardware drivers (like legacy Nvidia drivers or custom Wi-Fi modules) that only compile against a very specific, older kernel version, allowing Ubuntu to automatically delete it will instantly break your hardware on the next reboot.
You can instruct the apt package manager to hold (pin) specific kernels and permanently exempt them from the autoremove process.
How to Stop apt from Removing a Specific Kernel
The safest way to protect an old kernel is by using the apt-mark tool.
- Open your terminal application (
Ctrl+Alt+T). - First, find the exact package name of the kernel you want to protect. You can list all installed kernels by running:
dpkg --list | grep linux-image
- Identify the kernel you are currently using and want to keep (e.g.,
linux-image-5.15.0-43-generic). - To prevent Ubuntu from ever uninstalling or upgrading this specific package, apply a “hold” by running:
sudo apt-mark hold linux-image-5.15.0-43-generic
- (Optional) You should also hold the corresponding header files to ensure you can compile software against it later:
sudo apt-mark hold linux-headers-5.15.0-43-generic
Once a package is marked as held, the apt and unattended-upgrades services will treat it as untouchable. Even if you manually run sudo apt autoremove, your protected kernel will remain safely installed in the /boot directory, ensuring your custom hardware drivers never unexpectedly break.