Remove unused kernels

For regular Debian/Ubuntu, type:

for kernel in $(cd /boot; ls -1cr vmlinuz-* | head -n -1 | cut -f2,3 -d'-'); do
    sudo apt-get remove -y $(dpkg -l | egrep "^ii  linux-image-$kernel" | awk '{print $2}'); 
done

If you are using ProxMox, type:

for kernel in $(cd /boot; ls -1cr vmlinuz-* | head -n -1 | cut -f2,3 -d'-'); do
    sudo apt-get remove -y $(dpkg -l | egrep "^ii  pve-kernel-$kernel-pve" | awk '{print $2}'); 
done

Update the boot-loader

Always ensure the boot-loader is aware of any changes you’ve made.

sudo update-grub