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.
- Open your terminal application (
Ctrl+Alt+T). - Use the
nanotext editor to open the specific APT configuration file:
sudo nano /etc/apt/apt.conf.d/01autoremove-kernels
- (If that file does not exist on your specific Ubuntu version, try
sudo nano /etc/apt/apt.conf.d/50unattended-upgradesinstead). - 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";
- Change the word
"true"to"false". - Press
Ctrl+O, thenEnterto save the file. - Press
Ctrl+Xto exit thenanoeditor.
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.