I have old Linux kernel versions that I don't use so I was trying to remove them.
List of installed kernels from dpkg --list | grep linux-image
linux-image-5.4.0-26-generic (5.4.0-26.30)
linux-image-5.4.0-33-generic (5.4.0-33.37)
linux-image-5.4.0-37-generic (5.4.0-37.41)
Here are the steps to remove unused kernels.
Check what current kernel You run:
I am running
5.6.13-050613-lowlatency
List all installed kernels in Your OS:
Uninstall kernels You don't need:
You can try out this script
remove_old_kernels.sh
Run it like this for a dry run:
If all looks good, run it again like this:
Just use this:
To easily remove older versions kernels, e.g. kernels starting from 4.0 and so on.
An update to @alex Burdusel's script would be the following:
This solves the issue that it tries to delete the following packages:
autoremove
will only remove packages that are automatically installed. If you ever updated or added a kernel package manuallyautoremove
will not remove it. If you ever "held" a kernel versionautoremove
will not remove it. If you're wondering why Ubuntu is filling up your boot partition with kernels you no longer use it's likely one of these two reasons.Just taking Michal's answer a little further. I didn't want to type the kernels to delete everytime so I decided to use files instead.
Write all the current kernels you have on a file.
Filter your currently used kernel out of the file using grep.
Verify your current kernel is not present in the delete list. Don't skip this. Ensures you don't mistakenly delete all the kernels.
Delete all the unused kernels in one go.
Not one of these worked for me.
Had to use: