How to free up space in / boot partition on Ubuntu, Debian or Linux Mint

This article explains how to release Ubuntu, Debian, Linux Mint, Pop! _OS, the base OS, and space in the / boot partition on other Debian or Ubuntu-based Linux distributions.

Solution 1: Free up space in / boot partition when apt works

If apt works fine, you can usually remove unused old 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 will find various complicated commands online to remove old kernels, but I do not recommend you to use them because they may remove some unwanted things (see Andreas Jansson’s Comment on this answer E.g). should be apt autoremove Can work for a while, even Clear old kernel Utilities are now recommended apt autoremoveIf you want to use the old purge-old-kernels Utility bundled with Byobu (in newer versions, it only points to apt autoremove) You can find it Here. Another easy way to remove the old unused kernel is to use the Synaptic package manager to search for “linux-image” and “linux-header” and delete all versions except the currently used version. Alternatively, to be more volatile, you can keep the running version and the previous version and just delete the older kernel. You can see which kernel is currently in use by running:

uname -r

Another common Debian / Ubuntu / Linux Mint issue (and solution) you may be interested in: How to fix “Unable to acquire lock / var / lib / dpkg / lock-open (11 resources temporarily unavailable)” error

Solution 2: When the partition is full and apt is damaged, free up space in / boot.

In some cases, you may notice that the / boot partition is full during the system update, and you get an error when trying to use apt, No space left on device. When this happens, you cannot use apt to remove the old unused kernel. As a way around this, you can manually delete the kernel image from / boot. This guide contains an example that you must adapt to the currently running kernel version and unused older kernel versions.
If you can no longer boot Ubuntu because the disk is full, follow these steps Recovery mode (Restart the computer, hold down Shift (use BIOS) or Esc (use UEFI), enter the grub menu, then select recovery mode, and finally select the “Drop to root shell prompt” option).
First list 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 also need to know the current kernel version, so don’t delete it. This command should list the kernel distribution you are currently running:

uname -r

Example 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 the older versions 4.18.0-15 and 4.18.0-17 (these versions can be found in ls -l /boot command). You can manually delete each file from / boot, these files contain an earlier version than the currently running kernel (4.18.0-20 in my example), or you can run a command to remove the older kernel version All files. , Make sure you don’t include your current kernel in the list of files to delete! If you delete the wrong file, your computer won’t start! To delete all file files for kernel versions 4.18.0-15 and 4.18.0-17 at once (adapt the command to whatever kernel you are using and the earlier version to be deleted), use:

sudo rm /boot/*-4.18.0-{15,17}-*

Fix some or partial upgrades to make it work again:

sudo dpkg --configure -a
sudo apt install -f

Next, update Grub2 so that the old kernel no longer appears in the Grub boot menu:

sudo update-grub

Now you can automatically remove unused packages to clear all kernels that can be removed, and then proceed with the upgrade (if you have previously tried to upgrade but no free disk space / apt corrupted):

sudo apt autoremove
sudo apt upgrade

Source

Sidebar