If you have ever struggled with Ubuntu Server and the /boot/partition being filled up as a result of ‘apt upgrades’ then I’m with you.
For me until recently the process I use is as follows:
sudo apt update
sudo apt autoremove
sudo apt upgrade -y
Whilst autoremove gets rid of old Linux kernels, it will try to purge all but the latest two versions. However it won’t remove anything from version currently running.
Previously I took the approach of running apt upgrade -y before the (reboot then) purge, but I have tended to run out of disk space in /boot/ due to the number of updates to the operating system. Hence adding apt autoremove before hand.
Whilst have a mooch around the system I discovered that the following file, controls which versions of Linux are permitted to be purged, during autoremove:
/etc/apt/apt.conf.d/01autoremove-kernels
The file should not be manually edited, it is maintained by calling:
sudo /etc/kernel/postinst.d/apt-auto-removal
So, whilst it doesn’t solve all the problems with disk space and running apt. The process I use for updating the system is as follows:
sudo apt update
sudo apt autoremove -y
sudo apt update -y
.. if all goes well and reboot the system ..
sudo /etc/kernel/postinst.d/apt-auto-removal
sudo apt autoremove -y
This leaves the system running from the latest version of Linux, and only the previous one left in the /boot/ partition.
One last thing, following the apt autoremove, sometimes I get asked to reboot the system one final time. I’m guessing that this is some final housekeeping that the system thinks it needs.
I hope that this has made some sense, and you’ve gained from it.