Categories
Linux Servers

Not Enough Free Disk Space on Upgrade – Ubuntu 16.04

So a few months ago, I was having trouble installing updates on one of my Ubuntu Linux servers. When I ran, sudo apt-get upgrade I got the following error message listed below.

Not enough free disk space

The upgrade has aborted. The upgrade needs a total of 68.5 M free space on 
disk '/boot'. Please free at least an additional 68.5 M of disk space on 
'/boot'. Empty your trash and remove temporary packages of former 
installations using 'sudo apt-get clean'.

So I check the disk space by running, df -h and it showed that there was only 15mb left on the boot drive. For some reason, Ubuntu hasn’t been deleting the old kernel images once newer ones are installed.

To fix this, I first checked the current kernel version installed on my system by running the following command below.

uname -r 

And it outputted 4.15.0-64-generic. So when we start deleting old kernel images, we need to make sure we don’t delete this version.

Now, we need to list all of the kernel versions we have installed on the system by running the following command below.

sudo dpkg --list 'linux-image*'|awk '{ if ($1=="ii") print $2}'|grep -v `uname -r`

After you run the command above, the output should look something like this.

linux-image-4.15.0-64-generic
linux-image-4.15.0-16-generic
linux-image-4.15.0-25-generic
linux-image-extra-4.15.0-64-generic
linux-image-extra-4.15.0-16-generic
linux-image-extra-4.15.0-25-generic

Now we need to go through and delete all of the old kernel images installed. Be very careful to not delete the current kernel version that your system is using. Run uname -r to get the current version that your system is running and don’t delete it!

To delete old kernel, you’ll need to customize the following command.

sudo rm -rf /boot/[Old Kernel Version]

So in the following example above, we would need to remove two kernel versions by running the following commands below.

sudo rm -rf /boot/linux-image-4.15.0-16-generic
sudo rm -rf /boot/linux-image-4.15.0-25-generic

Now that we have more free space on the \boot drive, we’ll be able to fix what ever errors may have popped up.

sudo apt-get -f install

After that, we need to clean up all of the orphaned packages.

sudo apt-get autoremove

Then we’ll update the grub boot loader.

sudo update-grub

Now, we’ll update and upgrade the system.

sudo apt-get upgrade
sudo apt-get update
sudo apt-get dist-upgrade

And that’s it, your boot drive should now have enough space to install updates on your system.

Auto Remove Old Kernels

To ensure this doesn’t happen again, lets configure our system to automatically remove old kernels.

First, we need to install the unattended-upgrades package.

sudo apt-get install unattended-upgrades

Next, we need to configure unattended-upgrades to auto remove old kernel versions.

sudo nano /etc/apt/apt.conf.d/50unattended-upgrades

Scroll through the config file until you find the line listed below, and un-comment it (remove the //). Then save and exit the file.

Unattended-Upgrade::Remove-Unused-Dependencies "false";

Now you system will automatically remove old kernel versions by default and you should never have to worry about this again.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.