In ubuntu how to free up more space in /boot when /boot has no free disk space!

Have you ever encountered below error:

Error! Warning! The xxx MiB filesystem mounted at /boot has no free disk space!

many of you might also have encountered below error while doing apt-get command

Error: apt-get: No space left on device

the reason for the above error is your /boot partition is out of space and why does it happen? As mentioned in ubuntu help it happens because of –

LVM installs and encrypted installs use a separate /boot partition. The partition by default is capable of holding only four or five kernels, and can fill to capacity quickly. To prevent your /boot partition from getting full, you need to configure automatic removal of old kernels, or manually remove old kernels regularly.

Recently I came across such issue and I found plenty of answers of that, but none were directly helpful because my /boot parition had already 0 space and all of the approach needed to install some sort of dependency.

I did some more digging and followed below step to make it working.

please backup your system (for vps system you can create snapshot easily)

  1. List all kernels using below command:
    dpkg --list 'linux-image*'
  2. Display current kernel:
    uname -r
  3. List all kernels EXCEPT current one and Make sure your current kernel isn’t on that list.
    dpkg -l linux-{image,headers}-"[0-9]*" | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e '[0-9]'
  4. Remove all kernels EXCEPT current one:
    dpkg -l linux-{image,headers}-"[0-9]*" | awk '/^ii/{ print $2}' | grep -v -e `uname -r | cut -f1,2 -d"-"` | grep -e '[0-9]' | xargs sudo apt-get -y purge
    I was getting an error at step 4 and hence I had to do step 4.1
    1. Manually list and remove a few of old kernels using below commands:
      ls -lh /boot/*-3.13.0-119*;
      rm /boot/*-3.13.0-119*;
      replace 3.13.0 with your old kernel versions and double-check so you don’t mess up the existing kernel.
    2. After doing it update your grub (very important step as without this step when I continued I ended up the non-working system on reboot.
      sudo update-grub
    3. reboot the system and check its in working order, you may still see the same error and you can jump on step 5, no need to execute a command on step 4
  5. Clear other stuff:
    sudo apt-get autoremove --purge
    I was getting an error:
    E: Unmet dependencies. Try ‘apt –fix-broken install’ with no packages (or specify a solution).
    1. I had to do
      sudo apt --fix-broken install to fix it
    2. reboot the system and check its booting fine
    3. run command mentioned in step 5
  6. reboot the system, the system should boot fine and check /boot space it will have more free space.
  7. run sudo apt-get update and other commands mentioned in ubuntu help to setup auto cleanup and update to latest stable kernel

Reference url:

  • https://askubuntu.com/a/1053826/1094550
  • https://askubuntu.com/a/963646/1094550