I regularly delete old kernels leaving only the latest two entries using Synaptic.
I'm using Precise. However in my Grub "previous Linux version" menu there are quite a few entries labelled 2.6.8. I cannot find these linux-images in Synaptic.
dpkg -l | grep linux-image
Gives:
rc linux-image-3.0.0-17-generic 3.0.0-17.30
Linux kernel image for version 3.0.0 on x86/x86_64
ii linux-image-3.2.0-27-generic 3.2.0-27.43
Linux kernel image for version 3.2.0 on 32 bit x86 SMP
ii linux-image-3.2.0-29-generic 3.2.0-29.46
Linux kernel image for version 3.2.0 on 32 bit x86 SMP
ii linux-image-3.4.0-030400-generic 3.4.0-030400.201205210521
Linux kernel image for version 3.4.0 on 32 bit x86 SMP
ii linux-image-generic 3.2.0.29.31
Generic Linux kernel image
Sudo update-grub gives:
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.4.0-030400-generic
Found initrd image: /boot/initrd.img-3.4.0-030400-generic
Found linux image: /boot/vmlinuz-3.2.0-29-generic
Found initrd image: /boot/initrd.img-3.2.0-29-generic
Found linux image: /boot/vmlinuz-3.2.0-27-generic
Found initrd image: /boot/initrd.img-3.2.0-27-generic
Found linux image: /boot/vmlinuz-2.6.38-11-generic
Found initrd image: /boot/initrd.img-2.6.38-11-generic
Found linux image: /boot/vmlinuz-2.6.38-10-generic
Found initrd image: /boot/initrd.img-2.6.38-10-generic
Found linux image: /boot/vmlinuz-2.6.38-8-generic
Found initrd image: /boot/initrd.img-2.6.38-8-generic
Found memtest86+ image: /boot/memtest86+.bin
Found Windows Vista (loader) on /dev/sda1
sudo apt-get remove linux-image-2.6.8-8-generic gives:
E: Unable to locate package linux-image-2.6.8-8-generic
E: Couldn't find any package by regex 'linux-image-2.6.8-8-generic'
My boot folder contains the following:
abi-2.6.38-10-generic initrd.img-3.4.0-030400-generic abi-2.6.38-11-generic memtest86+.bin abi-2.6.38-8-generic memtest86+_multiboot.bin abi-3.2.0-27-generic System.map-2.6.38-10-generic abi-3.2.0-29-generic System.map-2.6.38-11-generic abi-3.4.0-030400-generic System.map-2.6.38-8-generic config-2.6.38-10-generic System.map-3.2.0-27-generic config-2.6.38-11-generic System.map-3.2.0-29-generic config-2.6.38-8-generic System.map-3.4.0-030400-generic config-3.2.0-27-generic vmcoreinfo-2.6.38-10-generic config-3.2.0-29-generic vmcoreinfo-2.6.38-11-generic config-3.4.0-030400-generic vmcoreinfo-2.6.38-8-generic extlinux vmlinuz-2.6.38-10-generic grub vmlinuz-2.6.38-11-generic initrd.img-2.6.38-10-generic vmlinuz-2.6.38-8-generic initrd.img-2.6.38-11-generic vmlinuz-3.2.0-27-generic initrd.img-2.6.38-8-generic vmlinuz-3.2.0-29-generic initrd.img-3.2.0-27-generic vmlinuz-3.4.0-030400-generic initrd.img-3.2.0-29-generic
and
ls -l /etc/grub.dyields:
total 56 -rwxr-xr-x 1 root root 6715 Apr 17 20:16 00_header -rwxr-xr-x 1 root root 5522 Oct 1 2011 05_debian_theme -rwxr-xr-x 1 root root 7407 May 17 09:22 10_linux -rwxr-xr-x 1 root root 6335 Apr 17 20:16 20_linux_xen -rwxr-xr-x 1 root root 1588 May 3 2011 20_memtest86+ -rwxr-xr-x 1 root root 7603 Apr 17 20:16 30_os-prober -rwxr-xr-x 1 root root 214 Oct 1 2011 40_custom -rwxr-xr-x 1 root root 95 Oct 1 2011 41_custom -rw-r--r-- 1 root root 483 Oct 1 2011 README
gdisk -l /dev/sda
yields:
Partition table scan: MBR: MBR only BSD: not present APM: not present GPT: not present *************************************************************** Found invalid GPT and valid MBR; converting MBR to GPT format. *************************************************************** Disk /dev/sda: 312581808 sectors, 149.1 GiB Logical sector size: 512 bytes Disk identifier (GUID): F832A498-05E1-4615-B5B1-757ACB4A757A Partition table holds up to 128 entries First usable sector is 34, last usable sector is 312581774 Partitions will be aligned on 2048-sector boundaries Total free space is 4183661 sectors (2.0 GiB) Number Start (sector) End (sector) Size Code Name 1 2048 61442047 29.3 GiB 0700 Microsoft basic data 3 163842048 169986047 2.9 GiB 8200 Linux swap 4 169986048 312578047 68.0 GiB 0700 Microsoft basic data 5 61444096 159666175 46.8 GiB 8300 Linux filesystem
Please help with removing the old and inexistent kernels from 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:
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
commandBy 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
After that, you will see only the latest kernel.
I usually just start Synaptic (which has to be installed separately these days), search for "linux" in the Installed category and mark all old versions of the kernel and linux-headers (i.e. all except the current one) to be removed. When uninstalled, they're removed from GRUB menu.
There must be a nifty single-line command to do that, but it feels safer just to do that manually
I suggest you enter this in a terminal session (Alt-Ctrl-T):
This command causes grub to use
os-prober
and to update the menu.If you have partitions with old Ubuntu releases on them that had used grub (it appears the OP had a natty release partition somewhere, maybe more) it's necessary to clean them up too before running update-grub on the current system.
os-prober
finds Windows and other Linux partitions. For other Linux partitions it copies the items from their grub menus, if any, rather than looking at their kernel files.If you have a really messed up configuration the best solution may be to boot your Ubuntu system and reinstall grub with:
While reinstalling grub it will recreate the
/etc/default/grub
and the/boot/grub/menu.cfg
file, based on the installed kernels in that partition and on the kernels installed in the grub configurations of other (presumably older) Ubuntu partitions (doesn't seem to be any for the OP).The slickest solution would be using
ubuntu-tweak
. After installation, fire it up, go toJanitor
, chooseOld Kernel
, select the old kernels you intend to remove andClean
. That's it! (Note that only old kernels show up in the janitor)For Ubuntu 12.04 LTS (Precise) 64bit (on non-PAE 32bit)
Check which versions are present:
Remove the oldest first, and don't remove current/latest version:
Re-check what version are now present. (Optional)
Note: This step is required, if you remove all but latest (or leave just one) version.
For Ubuntu 12.04 LTS (Precise) 32bit (PAE)
Check which versions are present:
Remove the oldest first, and don't remove current/latest version:
Re-check what version are now present. (Optional)
Note: This step is required, if you remove all but latest (or leave just one) version.