Free up space in /boot – Ubuntu or Debian

Today, Ubuntu, prompted me to free up space in my boot folder, so that it can update my kernel.

What did I do? I just deleted files and had free space. Sounds simple right?

But, /boot can be a bit complicated to deal with and if an important file is deleted, you will never be able to boot your computer (don’t worry you actually don’t have to install your OS again).

So, there were too many files in the /boot folder. But I know that, I can use only 1 version of the kernel and boot files right? So what were all the other versions for?

BTW, use uname -r in your terminal to list out your current kernel version.

uname -r

To find out the kernel versions that are installed but are not in use, type the following command in your terminal.

sudo dpkg -l linux-{image,headers}-“[0-9]*” | awk ‘/^ii/{ print $2}’ | grep -v -e `uname -r | cut -f1,2 -d”-“` | grep -e ‘[0-9]’

To delete all the above files, pipe the output of the above to

sudo apt-get -y purge

Final command to delete unused files

sudo 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

This worked like a charm for me. In case of issues, please let me know in the comments below.

Leave a Reply

Your email address will not be published. Required fields are marked *