Claiming back space on /boot (Ubuntu Server 16.04)

I was getting a bunch of errors when trying to update my system, and updates were failing. It asked me to run sudo apt-get -f install to resolve but still failed. The relevant part of the error is below:

dUnpacking linux-image-4.4.0-127-generic (4.4.0-127.153) ...
dpkg: error processing archive /var/cache/apt/archives/linux-image-4.4.0-127-generic_4.4.0-127.153_amd64.deb (--unpack):
 cannot copy extracted data for './boot/vmlinuz-4.4.0-127-generic' to '/boot/vmlinuz-4.4.0-127-generic.dpkg-new': failed to write (No space left on device)
No apport report written because the error message indicates a disk full error

Basically, cannot write to /boot as there is no space. Can be confirmed with df -h

$ df -h
Filesystem                                  Size  Used Avail Use% Mounted on
udev                                        3.8G     0  3.8G   0% /dev
tmpfs                                       769M  9.1M  760M   2% /run
/dev/mapper/chipshop--vg-root                25G   16G  7.2G  69% /
tmpfs                                       3.8G   12K  3.8G   1% /dev/shm
tmpfs                                       5.0M     0  5.0M   0% /run/lock
tmpfs                                       3.8G     0  3.8G   0% /sys/fs/cgroup
/dev/sda2                                   473M  464M     0 100% /boot
/dev/sda1                                   511M  3.4M  508M   1% /boot/efi
/dev/mapper/chipshop--data-chipshop--media  2.5T  2.3T   39G  99% /data/media
tmpfs                                       769M     0  769M   0% /run/user/1000

I think this is caused when upgrading an old OS to the new version. Fresh installations don't have their partitions set up in this way so possibly don't suffer this issue.

The /boot partition is not part of a Logical Volume and I don't think it can be easily given more space.

I tried to purge some of the old image files, but apt was unable to do so due to existing dependancies..

$ dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve $kernelver
linux-headers-4.4.0-103
linux-headers-4.4.0-103-generic
linux-headers-4.4.0-104
linux-headers-4.4.0-104-generic
linux-headers-4.4.0-108
linux-headers-4.4.0-108-generic
linux-headers-4.4.0-109
linux-headers-4.4.0-109-generic
linux-headers-4.4.0-112
linux-headers-4.4.0-112-generic
linux-headers-4.4.0-116
linux-headers-4.4.0-116-generic
linux-headers-4.4.0-119
linux-headers-4.4.0-119-generic
linux-headers-4.4.0-124
linux-headers-4.4.0-124-generic
linux-image-4.4.0-103-generic
linux-image-4.4.0-104-generic
linux-image-4.4.0-108-generic
linux-image-4.4.0-109-generic
linux-image-4.4.0-112-generic
linux-image-4.4.0-116-generic
linux-image-4.4.0-119-generic

So I navigated to the /boot folder and manually removed some of the oldest, unused kernel images:

$ cd /boot
/boot$ sudo rm vmlinuz-4.4.0-103-generic
/boot$ sudo rm vmlinuz-4.4.0-103-generic.efi.signed
/boot$ sudo rm abi-4.4.0-103-generic
/boot$ sudo rm initrd.img-4.4.0-103-generic
/boot$ sudo rm System.map-4.4.0-103-generic

I repeated this for linux-headers-4.4.0-104, this gave me around 10% free disk space

I then ran sudo apt-get purge linux-image-4.4.0-103 linux-image-4.4.0-104 to remove these two packages from apt as their files had already been manually removed.

I was then able to finally run sudo apt-get -f install this ran through and removed unneeded packages, resulting in around 40% free disk space on the /boot partition

This was caused by not regularly running sudo apt-get autoremove, which is suggested by apt every time I update, but I ignored...

https://askubuntu.com/questions/171209/my-boot-partition-hit-100-and-now-i-cant-upgrade-cant-remove-old-kernels-to/171225#171225

https://askubuntu.com/questions/89710/how-do-i-free-up-more-space-in-boot