We've shown you how to clean up your messy Ubuntu boot menu before, but if you'd like to avoid manually uninstalling old kernels, this handy bash script will do it all for you.
After you've had one Ubuntu installation for awhile, you start to build up a long list of old kernels installed on your system. Not only to they clutter up your boot menu, but they also take up space on your hard drive. While you could uninstall each kernel one by one from Synaptic, this bash script will uninstall them with just a quick Terminal command.
Copy the code below and paste it into a text editor, saving the file as cleanKernels.sh:
#/bin/bash ls /boot/ | grep vmlinuz | sed '[email protected]@[email protected]' | grep -v `uname -r` > /tmp/kernelList for I in `cat /tmp/kernelList` do aptitude remove $I done rm -f /tmp/kernelList update-grub
Now, whenever you feel your boot menu is getting a little messy, just open up a Terminal and run sudo bash /path/to/cleanKernels.sh to clean it up (where /path/to/ is the path to wherever you saved the script).
I tried this on my system and the script ran fine, but my current Ubuntu installation is so new that I don't have any other kernels installed right now—so try it out and let us know in the comments how it works for you!
Clean Up Your Grub Menu and the Kernels You Do Not Use [Linux Operating System via Ubuntu Forums]