Read all the answer before executing the commands.
How I did it :
First get the kernal you are using
uname -r
List the kernels, and note down the kernel that is just older (version 5.15.0-35 when you run the 5.15.0-36 - see the 35 and 36 at the end?) and another one: 5.14.0-46 (the latest of the 5.14 serie). That way, you want to keep two versions to revert to if needed).
(as a reminder : grep -v : if you want to find something which doesn’t match a given pattern, grep allows doing just that with -v flag)
dpkg --list | egrep -i 'linux-image|linux-headers'
Remove the kernel unwanted. Note that the
sudo apt-get --purge remove $(dpkg --list | egrep -i 'linux-image|linux-headers' | awk '/ii/{ print $2}' | grep -v `uname -r` | grep -v 5.15.0-35 | grep -v 5.14.0-46 )
the following might not be necessary, but it freed up space for me too - even if it should be the same than the set of command before
dpkg -S "linux-image"
sudo apt-get --purge remove $(dpkg -S "linux-image" | cut -f'1' -d':' | grep -v 5.11 | grep -v 5.15.0-35 | grep -v 5.14.0-46 )
At the end, do :
sudo apt autoremove
sudo apt-get autoremove
should do the trick on Ubuntu 14.04+sudo apt-get autoremove --purge
the answer by following theapt-mark
advice on https://help.ubuntu.com/community/RemoveOldKernels