Removing old kernel entries in Grub

  • Open up a terminal (Ctrl+Alt+T).

  • Type uname -r. This will show you the kernel you're using currently, so you don't want to remove this.

  • Run the following command: dpkg --list | grep linux-image. This will show the all the kernels that are installed.

  • Note down the names of all the kernels which you want to remove.

  • To remove the kernels, run: sudo apt-get purge linux-image-x.x.x.x-xyz (replace the kernel name with an appropriate one).

  • Update the GRUB: sudo update-grub2

And, you're done.

Bonus: here's a little one-liner to do all that automatically:

sudo apt-get purge $( dpkg --list | grep -P -o "linux-image-\d\S+" | grep -v $(uname -r | grep -P -o ".+\d") )

I found what this problem was.

The issue was that, when I upgraded Ubuntu, by installing through a liveUSB instead of doing a normal upgrade, it left behind the old kernel files in the /boot folder.

Now that I have upgraded in the same way from 12.10 to 13.04, I encountered the same situation.

The solution is to manually delete all the files related to the old kernels in the /boot folder and run sudo update-grub. The extra entries vanished.


Try this command. It's a refined version of the same apt-get remove command

sudo apt-get autoremove linux-image-3.2.0-23-generic-pae

By replacing remove with autoremove, the removal process automatically finds and removes other dependencies left as well, so you will get a clean uninstallation, rather than having to go here and there and delete the leftovers.

Repeat the process for other old kernels as well.

After that, run

sudo update-grub

After that, you will see only the latest kernel.

Tags:

Kernel

Grub2