Clearing Out /boot

The /boot partition sometimes needs a bit of attention. If you enable automatic updates, it will fill up with old kernels that you'll probably never need. It also will stop you from running aptitude to install or remove anything. If you find yourself in this situation, you can use dpkg to get around it. dpkg is the higher-level package manager in Debian-based distributions, and it's very useful when aptitude has broken.

To see the status of your partitions, run: df -h:


Filesystem      Size  Used Avail Use% Mounted on 
udev            3.0G   12K  3.0G   1% /dev 
tmpfs           597M  528K  597M   1% /run 
/dev/dm-0        97G   14G   78G  15% / 
none            4.0K     0  4.0K   0% /sys/fs/cgroup 
none            5.0M     0  5.0M   0% /run/lock 
none            3.0G     0  3.0G   0% /run/shm 
none            100M     0  100M   0% /run/user 
/dev/sda1       228M  219M     0 100% /boot 

If you look in the directory /boot, you will see it full of old kernels and images. It is not advisable just to delete them, as you can break your system. Run uname -r, which will tell you what kernel you are currently on:


3.13.0-137-generic 

Let's find out which kernels are installed and which can be purged from your system. To do this, run the following:


dpkg --list "linux-image*" | grep -v $(uname) | grep ii 

This will use dpkg to list all Linux kernel images (excluding the one you are using) that are installed.

The output still might be quite long, so let's refine it by piping the results in to awk. The awk command below is an instruction to print the second column from the output:

 
dpkg --list "linux-image*" | grep -v $(uname -r) | 
 ↪grep ii | awk '{ print $2 }' 

This provides a list to work with, and you can stick this in a script or run it from the command line to purge them all.

Caution: make sure the kernel you are using is not in the list. We should have eliminated that when we specified grep -v $(uname -r). The -v tells grep to exclude anything that contains the output of uname -r.

If you are happy and have sudo privileges, go ahead:


sudo dpkg --purge $(dpkg --list "linux-image*" | grep -v 
 ↪$(uname -r) | grep ii | awk '{ print $2 }') 

To finish off, run sudo update-grub2. This will ensure that grub is updated with the available kernels. Otherwise, you may be heading for trouble. Then fix aptitude by running sudo apt-get -f install, followed by sudo apt-get autoremove to clear the images out of aptitude.

Look at your partition, and you will see it has free space:


Filesystem      Size  Used Avail Use% Mounted on 
udev            3.0G   12K  3.0G   1% /dev 
tmpfs           597M  528K  597M   1% /run 
/dev/dm-0        97G   13G   79G  14% / 
none            4.0K     0  4.0K   0% /sys/fs/cgroup 
none            5.0M     0  5.0M   0% /run/lock 
none            3.0G     0  3.0G   0% /run/shm 
None            100M     0  100M   0% /run/use 
/dev/sda1       228M   98M   118M  46% /boot 

—Adam McPartlan