How can I remove old kernels/install new ones when /boot is full [debian/ubuntu]

In a terminal, execute the following command:

dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

This command lists all currently installed Linux kernels, then selects all of the ones that are currently not used and removes them.


apt-get autoremove

After, you should also sudo update-grub when you are finsihed.

sudo apt-get -f install