Tested on: Debian 12, Ubuntu 24.04 LTS
Old kernels accumulate in /boot after updates. When the partition fills up, kernel updates fail and apt may stop working.
df -h /boot
uname -r
Never remove the running kernel. After a kernel update, reboot first and make sure the new kernel works (uname -r shows the newest version) before removing old ones.
sudo apt autoremove --purge
apt keeps the running kernel and the newest ones and removes older kernels that were installed automatically with updates. Kernels installed manually are not removed — use the manual method below.
List installed kernels (metapackages such as linux-image-amd64 or linux-image-generic are excluded on purpose — removing them stops kernel updates):
dpkg -l 'linux-image-[0-9]*' | awk '/^ii/ {print $2}'
Kernel names look like linux-image-6.8.0-40-generic on Ubuntu and linux-image-6.1.0-26-amd64 on Debian — use the names from your list.
Remove an old kernel and its headers, replacing the version with one from the list:
sudo apt purge linux-image-6.8.0-40-generic linux-headers-6.8.0-40-generic
sudo apt autoremove --purge
Keep at least one previous kernel as a fallback. GRUB is updated automatically after removal.
When apt cannot finish an operation because /boot has no space, remove one old kernel (not the running one — check uname -r) directly with dpkg, then let apt repair itself:
sudo dpkg --purge linux-image-6.8.0-40-generic
sudo apt -f install
sudo apt autoremove --purge
df -h /boot # Free space increased
dpkg -l 'linux-image-[0-9]*' | awk '/^ii/ {print $2}' # Should list only the current and previous kernels