Recently, I was performing some server maintenance on my home lab, a Lenovo ThinkServer TS140 running Ubuntu that I have as a dedicated Plex media server. When I first set it up, I installed Ubuntu 16.04 LTS and I finally decided to upgrade from 16.04 to Ubuntu 20.04. However, when I attempted to run a full operating system (OS) upgrade, I got an error that there was not enough space. As such, I realized that I'd need to clean the boot partition. Learn how to free up more space in boot on Ubuntu, and why your Ubuntu boot partition may be full!
What is the Boot Partition on Linux and Why do You Need to Free Up Boot Space?
On Ubuntu and other Debian-based Linux distributions (distros), the boot partition stores various files required to boot up your OS. The boot partition is mounted to the aptly-named /boot directory. Among the various files you'll find in your Ubuntu Linux boot partition are GRUB bootloader configuration files.
It's likely that your Ubuntu boot partition is low on space because of old OS kernels. A kernel is software that manages your hardware and enables application libraries as well as software to run across a variety of different hardware options. As you perform updates, old kernels can pile up in the boot directory requiring you to clean the boot partition. If you've never run an Ubuntu cleanup, you could get pretty low on /boot space which will cause your system to become unstable.
How to Free Up Space on Ubuntu Boot Drive - Remove Old Kernels in Ubuntu
Freeing up disk space on your boot partition is pretty simple. You can manually remove old kernels, or configure automatic maintenance. On Ubuntu 16.04 and later, unattended-upgrades should be enabled by default, although it never hurts to double-check with a manual Ubuntu partition clean up. First, update the list of available packages as well as their versions and upgrade the software packages:
sudo apt-get update && upgrade
Next up, use the autoremove command to remove old Linux kernels in Ubuntu:
sudo apt-get autoremove --purge
This should automatically free up boot partition space on your system. Alternatively, you can manually remove kernels. You can get a list of all installed kernels using:
dpkg -l linux-image-\* | grep ^ii
But you'll want to avoid removing the currently running kernel. So you can list all Ubuntu Linux OS kernels and headers aside from the kernel you're currently running with:
kernelver=$(uname -r | sed -r 's/-[a-z]+//') dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve $kernelver
You can combine this with the purge command to remove all of your old Ubuntu kernels:
sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")
Once that's complete, you should have freed up space by removing old kernels on Ubuntu.
How to Free Up Space on the Ubuntu Boot Partition - Final Thoughts
If you want to keep your Linux PC or server running smoothly, it's important to keep up with regular maintenance. This includes running software updates, operating system upgrades, and freeing up space on partitions frequently. Luckily, if your Linux machine is bogged down by a bunch of old kernels, it's easy enough to remove them with a few simple commands and fix your boot partition when it's full.
Top comments (0)