How to Stop Ubuntu from Automatically Removing Old Kernel Versions After Updates

When Ubuntu downloads and installs a major system update, it often includes a new version of the Linux kernel. Because the kernel is the core of the operating system, booting into a new one always carries a slight risk of hardware incompatibility. To protect against this, Ubuntu’s package manager (APT) is designed to keep the currently running kernel and at least one previous version installed as a fallback.

However, once you successfully boot into the new kernel, the system will eventually run an “auto-remove” process in the background. This process deletes older, unused kernels to free up disk space in your /boot partition. While usually harmless, if you rely on a specific older kernel version because a proprietary Wi-Fi or graphics driver breaks on newer releases, this automatic deletion will ruin your system.

You can instruct the package manager to stop automatically removing old kernels.

How to Disable Kernel Auto-Removal in Ubuntu

The rule that governs automatic kernel deletion is stored in a configuration file within the APT directories.

  1. Open your terminal application (Ctrl+Alt+T).
  2. You need to edit the APT configuration file with root privileges. Open it using nano:

sudo nano /etc/apt/apt.conf.d/01autoremove-kernels

  1. Note: If you do not see this exact file, you may need to edit /etc/apt/apt.conf.d/01autoremove instead, depending on your specific Ubuntu version.
  2. Scroll through the file until you find a section that defines the rules for removing kernels. However, manually editing these complex regex rules is prone to error.
  3. The safest and most reliable way to prevent a specific kernel from ever being deleted is to use the apt-mark command instead of hacking the config file. Close nano (Ctrl+X).
  4. To lock a specific kernel version (for example, version 5.15.0-43-generic), tell APT to “hold” it:

sudo apt-mark hold linux-image-5.15.0-43-generic
sudo apt-mark hold linux-headers-5.15.0-43-generic

What This Does

By placing a “hold” on the specific kernel packages you rely on, the APT package manager is strictly forbidden from upgrading, modifying, or auto-removing them. The rest of your system (including newer kernels) will continue to update normally, but your safe fallback kernel will permanently remain in the GRUB boot menu until you manually unhold it (sudo apt-mark unhold [package-name]).

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.