How to Stop Ubuntu from Automatically Removing Old Kernels (Autoremove)

When you use the Advanced Packaging Tool (APT) to update your Ubuntu system (sudo apt upgrade), the package manager frequently installs new, upgraded Linux kernels. Over time, these old kernels build up in your /boot directory, consuming valuable disk space.

To prevent the /boot partition from filling up and causing a system crash, modern Ubuntu systems run an automated background script (via unattended-upgrades or an APT hook) that periodically runs apt autoremove --purge to silently delete older kernels, keeping only the two most recent versions.

While this is great for desktop users, it can be risky for server administrators. If a new kernel update introduces a severe bug that breaks a proprietary graphics driver or a specific RAID controller, you rely on those older, stable kernels in the GRUB menu to boot the system. If Ubuntu automatically deleted your known-good kernel, your system may be permanently unbootable.

You can instruct the package manager to stop automatically marking old kernels for removal.

How to Disable Automatic Kernel Removal

You need to modify the global APT configuration file that handles automated cleanup.

  1. Open your terminal application (Ctrl+Alt+T).
  2. Use the nano text editor to open the specific APT configuration file:

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

  1. (If that file does not exist on your specific Ubuntu version, try sudo nano /etc/apt/apt.conf.d/50unattended-upgrades instead).
  2. Scroll through the file and look for a line that resembles:

Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";
or
Unattended-Upgrade::Remove-Unused-Dependencies "true";

  1. Change the word "true" to "false".
  2. Press Ctrl+O, then Enter to save the file.
  3. Press Ctrl+X to exit the nano editor.

From this point forward, Ubuntu will indefinitely hoard all compiled kernels in the /boot partition. You must now take manual responsibility for running sudo apt autoremove yourself whenever your disk space begins to run low.

Get the best tech tips delivered straight to your inbox.

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