How To Free Up Space In The /boot Partition On Ubuntu, Debian, Or Linux Mint
This article explains how to free up space in the /boot partition on Ubuntu, Debian, Linux Mint, Pop!_OS, elementary OS, and other Debian or Ubuntu based Linux distributions.
If apt is working, you can usually remove old, unused kernels by running:
Example:
You'll find various complicated commands online for removing old kernels, but I don't recommend using them as they may remove some unwanted stuff (see Andreas Jansson's comment on this answer for example). Supposedly
If you want to use the old
An alternative, easy to use way of removing old, unused kernels is to use Synaptic Package Manager to search for "linux-image" and "linux-headers", and remove all but the version you're currently using. Or, to be more precarious, you could leave the the running and previous version installed, and only remove older kernels. You can see the kernel that's currently in use by running:
Another common Debian / Ubuntu / Linux Mint problem (and solution) you might be interested in: How To Fix "Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)" Errors
In some situations you might notice that your /boot partition got full in the middle of a system update, getting an error when trying to use apt which says
In case you can no longer boot Ubuntu because the disk is full, follow the procedures below from the recovery mode (reboot your computer, hold the Shift (with BIOS), or Esc (with UEFI), key to get to the grub menu, then select recovery mode, and finally choose the "Drop to root shell prompt" option).
Start by listing all available kernels in /boot:
Sample output:
You'll also need to know the version of the kernel you're currently using, so you don't delete it. This command should list your currently running kernel release:
Example with output:
In this case, the computer is running Linux version 4.18.0-20, so we can remove older versions 4.18.0-15 and 4.18.0-17 (these versions can be seen in the output of the
Before using this command, make sure you don't include your current kernel in the list of files to be deleted! If you delete the wrong files your computer will not boot!! To remove all files files for kernel versions 4.18.0-15 and 4.18.0-17 in one go (adapt the command to whatever kernel you're using and what older versions you want to remove), use:
Fix broken or partial upgrades to get apt working again:
Next, update Grub2, so the old kernels are no longer displayed in the Grub boot menu:
Now you can autoremove unused packages to clear out any kernels that can be removed, and continue with the upgrade (if you were previously trying to upgrade, but failing to to no disk space being available / apt being broken):
Solution 1: Free up space in the /boot partition when apt is working
If apt is working, you can usually remove old, unused kernels by running:
sudo apt autoremove
Example:
$ sudo apt autoremove
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
linux-headers-4.18.0-15 linux-headers-4.18.0-15-generic
linux-image-5.0.0-11-generic linux-modules-4.18.0-15-generic
linux-modules-extra-4.18.0-15-generic
0 upgraded, 0 newly installed, 5 to remove and 0 not upgraded.
After this operation, 334 MB disk space will be freed.
Do you want to continue? [Y/n]
You'll find various complicated commands online for removing old kernels, but I don't recommend using them as they may remove some unwanted stuff (see Andreas Jansson's comment on this answer for example). Supposedly
apt autoremove
works correctly for some time, and even the purge-old-kernels utility now recommends using apt autoremove
.If you want to use the old
purge-old-kernels
utility that was bundled with Byobu a while back (in newer versions it just points to apt autoremove
), you can find it here.An alternative, easy to use way of removing old, unused kernels is to use Synaptic Package Manager to search for "linux-image" and "linux-headers", and remove all but the version you're currently using. Or, to be more precarious, you could leave the the running and previous version installed, and only remove older kernels. You can see the kernel that's currently in use by running:
uname -r
Another common Debian / Ubuntu / Linux Mint problem (and solution) you might be interested in: How To Fix "Could not get lock /var/lib/dpkg/lock - open (11 Resource temporarily unavailable)" Errors
Solution 2: Free up space in /boot when the partition is full and apt is broken.
In some situations you might notice that your /boot partition got full in the middle of a system update, getting an error when trying to use apt which says
No space left on device
. When this happens you can't remove old, unused kernels using apt. As a way to fix this you can manually remove the kernel images from /boot. This guide contains an example which you'll have to adapt for your current running kernel version and old, unused kernel versions.In case you can no longer boot Ubuntu because the disk is full, follow the procedures below from the recovery mode (reboot your computer, hold the Shift (with BIOS), or Esc (with UEFI), key to get to the grub menu, then select recovery mode, and finally choose the "Drop to root shell prompt" option).
Start by listing all available kernels in /boot:
ls -l /boot
Sample output:
$ ls -l /boot
total 242072
-rw-r--r-- 1 root root 217065 Feb 7 11:10 config-4.18.0-15-generic
-rw-r--r-- 1 root root 218068 Mar 14 16:01 config-4.18.0-17-generic
-rw-r--r-- 1 root root 218350 May 8 09:14 config-4.18.0-20-generic
drwxr-xr-x 5 root root 4096 Jun 3 13:07 grub
-rw-r--r-- 1 root root 59618395 May 17 13:25 initrd.img-4.18.0-15-generic
-rw-r--r-- 1 root root 39897502 Jun 3 13:05 initrd.img-4.18.0-17-generic
-rw-r--r-- 1 root root 39897454 Jun 3 13:05 initrd.img-4.18.0-20-generic
-rw-r--r-- 1 root root 182704 Jan 28 2016 memtest86+.bin
-rw-r--r-- 1 root root 184380 Jan 28 2016 memtest86+.elf
-rw-r--r-- 1 root root 184840 Jan 28 2016 memtest86+_multiboot.bin
-rw------- 1 root root 4268435 Feb 7 11:10 System.map-4.18.0-15-generic
-rw------- 1 root root 4268612 Mar 14 16:01 System.map-4.18.0-17-generic
-rw------- 1 root root 4270411 May 8 09:14 System.map-4.18.0-20-generic
-rw------- 1 root root 8543992 Feb 7 13:27 vmlinuz-4.18.0-15-generic
-rw------- 1 root root 8548088 Mar 14 14:39 vmlinuz-4.18.0-17-generic
-rw------- 1 root root 8556280 May 8 09:16 vmlinuz-4.18.0-20-generic
You'll also need to know the version of the kernel you're currently using, so you don't delete it. This command should list your currently running kernel release:
uname -r
Example with output:
$ uname -r
4.18.0-20-generic
In this case, the computer is running Linux version 4.18.0-20, so we can remove older versions 4.18.0-15 and 4.18.0-17 (these versions can be seen in the output of the
ls -l /boot
command). You can remove each file from /boot containing an version older than the current running kernel (older than 4.18.0-20 in my example) manually, or you can run a command to remove all files for older kernel versions.Before using this command, make sure you don't include your current kernel in the list of files to be deleted! If you delete the wrong files your computer will not boot!! To remove all files files for kernel versions 4.18.0-15 and 4.18.0-17 in one go (adapt the command to whatever kernel you're using and what older versions you want to remove), use:
sudo rm /boot/*-4.18.0-{15,17}-*
Fix broken or partial upgrades to get apt working again:
sudo dpkg --configure -a
sudo apt install -f
Next, update Grub2, so the old kernels are no longer displayed in the Grub boot menu:
sudo update-grub
Now you can autoremove unused packages to clear out any kernels that can be removed, and continue with the upgrade (if you were previously trying to upgrade, but failing to to no disk space being available / apt being broken):
sudo apt autoremove
sudo apt upgrade