Every time Ubuntu installs a new Linux kernel, the old one is left behind. This means that if you are regularly updating an Ubuntu system the Grub boot menu becomes longer and longer with kernels you don’t need anymore.

The old kernels are deliberately left installed and on the menu so you can boot a previous kernel if you have trouble with a new one. But if the new one works, you can safely uninstall the old kernel, which will also result in the Grub menu being cleaned up.

First you need to find out what your current kernel is. Open a terminal and run the following command:

uname -r

It will print the version of the Linux kernel you are running, this is the one you want to keep. It should look something like this:

2.6.20-16-generic

Open the Synaptic package manager from the System->Administration menu.

Click the “Search” button on the tool bar and search for linux-image-2.

The results should show every available and installed kernel. A green box on the left indicates that the package is installed. The only linux-image you want installed is the latest one. Find the package corresponding to the kernel to you running currently (this is the kernel you found in the terminal window). Make sure you keep that one. Now you can uninstall the old kernels from the list by clicking their boxes and selecting “Mark for Removal”.

Caution! Be careful of what you remove. Ensure that you don’t remove your current kernel, or anything that is not a linux-image. It is possible to break Ubuntu if you remove the wrong kernel.

Great Cool !but what if i break the system,i wud prefer to keep the kernel unless the list remains slim.I think there’s a GReat Need Now for ubuntu thinking about System restore feature of Xp.There is alternative,u can delete the entries from GRub wont hurt.Keep Ubuntu”’ing.

Installed hardy over gutsy, from the net update download. Found both 2.5.22.14 and 2.6.24.16 loaded in grub. Would not boot with 24.16 only with 22.14. Spent hours on forums to attempt to correct. Lucky found this site and the simple logical solution. Removed 22.14 and all is well. Thanks from me – a newbie!

Thanks for the clear instructions for ubuntu. I just switched from XP and so, so much of linux/ubuntu instruction out there is not geared toward those of us who didn’t have LINUX as our first language growing up.

After installing new kernel I choose this kernel in grubmenu and see ubuntu download. But… Suddenly the screen switches off (gets dark). The onle thing I can do then, is to press reset button in order to reboot and choose the old kernel. Why doesn’t the new one work?

Thanks, my grub menu was getting really full with all the different kernels and sometimes I boot to my windows xp install and it was no longer even on the first screen. Got some of the old kernels removed now, thanks. I keep the 2nd to oldest for backup just in case. Its saved me before.

I’m also starting to collect old kernels, which really clutter up my GRUB start menu, but what about the other old packages? Other than removing everything that is linux-image, as per the article’s instructions, do you remove the other kernel-specific files that do not have “linux-image” in their names?

E.g., would the removal list would look like:
linux-image-XXX-generic
linux-headers-XXX
linux-headers-XXX-generic
linux-restricted-modules-XXX-generic
where XXX is the older version(s)

Thanks for the help. I then got a dialog asking what to do about the Grub menu. I really didn’t know what option to choose so I picked to keep the list as it is. I know I can manually edit it, but it would have been nice to see an option like: “Update to include only installed Kernels” or something like that.

This cleared some things up for me. I had been manually editing my grub list to remove older kernels entries, but not actually removing the old kernels from Ubuntu. LOL, everytime I upgraded my grub list was repopulated with all of the outdated kernels, which were #rem out. At least now I know why it was being repopulated, and how to keep it slim and trim. I’ve got a dual boot setup between Ubuntu and Vista/XP where Ubuntu is on an old IDE drive and Vista/XP are on a raid setup. I’m going to print my grub list before removing the any entries just in case it overwrites my Vista/XP entry.

This information is for ONLY 10.04. I do not speak for older versions of the OS since 9.10 would install but would not display properly with my brand new ASUS VH242HL-P monitor so I immediately downloaded 10.04 and it worked just great vis-a-vis the monitor. The upgrade was not by choice – my old ViewSonic monitor died.

1. It does not automatically remove older kernels if you use the automatic update mechanism (the one that informs you when you need something new). I installed the OS in June and here at the end of July I had three Linux kernels with only two needed (one as a backup in case the new kernel causes problems). However the “uname -r” command gave back 2.6.32-24-generic-pae and used the recommended “linux-image-2″ in the Synaptic package manager. Synaptic showed all three of them and allowed me to easily pick the oldest kernel and remove it.

2. GRUB 2.x is vastly different than GRUB 1.x. I haven’t rebooted yet after doing the previous but from the log (I watched it remove it), Synaptic did the requisite GRUB hocus pocus (update-grub). But after looking at the plethora of files in /boot/grub I am seeing that just adding a simple (an example where Windows is on the first partition, Ubuntu on the second, and DesktopBSD is on the third):

title DesktopBSD
root (sd0,3,a)
kernel /boot/loader

in the old menu file like I used to do to get it to boot DesktopBSD after I get DesktopBSD installed will no longer be possible. It ain’t going to be nearly as easy getting it going as it was under GRUB 1.x. If you want to be sure things get upgraded in GRUB 2.x make sure you do a manual sudo update-grub after you remove an old kernel to make sure it gets the update. Look into the /boot directory (folder) and as long as the old kernel you removed has all of the files gone it will update for Ubuntu just fine. I actually do a sudo of an xterm but that means I have to do other changes as well. See my “Sudo Won’t Do” at my SecureMecca.BlogSpot.com blog for work arounds.

3. You will have a HUGE GRUB menu with three Linux kernels, Windows, and those memtests. I am sure this information is some place else but doing the following will get rid of the memtests (using a $ to indicate an xterm prompt):

Also see the GRUB 2 comments below. My only comment was that GRUB 1.x worked just fine for me. Now I have a zillion files with no idea of how to do anything any more. How is that an improvement? I will say that once you do the update-grub it will handle the multiple versions of the Linux kernel just fine.

My main comment is that this comment needs to be removed. We need to collapse things into a best of the best and I don’t fifteen different ways of mounting a FAT32 partition that are all wrong. We also need far less changes (evolutionary change) instead of a huge number of radical changes (revolutionary change) and consistency across distributions with many components having the exact same name (call evince evince and STICK WITH IT! This is a plea to the Linux creators to get rid of what I see as a Tower of Babel.

I just removed all the old kernel-specific files (except for the current and previous one), and things restarted just fine. Since I’m running with only 20 GB of disk space, the half a gig of removed files is good.

For some reason, Synaptics doesn’t show the kernels when I search for “linux-image-2″ but it does when I take of the “-2″ although all the packages do begin with “linux-image-2″. Just a weird little thing I wanted to point out.

to answer some of the questions in the comments -
[reposting as the <kernel number> were stripped]

1 to automatically update the list of kernels there are 2 ways
A the best is to upgrade to grub-2
sudo apt-get install grub2
B when you are given a list of alternatives how to modify /boot/grub/menu.lst, look at the ‘side-to-side difference’; although you’ll need to understand how to read a diff file for that, it’s relatively self-evident; alternatively normally ‘install the package maintainer’s version’ is quite sufficient, as it is usually a list derived from kernels + alternate OS’s found

In some cases keeping an old kernel might make sense.
having an old kernel installed with drivers not available anymore makes it able to use “old/unsupported” hardware for a longer time. that is, until kernel and userland start diverging too much.

This is also a good way to remove the NEW kernel when it does not work. For example, with 10.04 LTS I have been experiencing with random freezes with all kernels past 2.6.32-21-generic. I used Synaptic to remove the new kernels and have no more freezes.

I am against autoremove …
I have many things installed which apt says they have been done so automatically and which are actually being used, but apt says could be removed by itself..
for this obviously there could be made a application usage monitor, yet another agent that slows the system down.

i have 3 kernels on my ubuntu 10.10 (2.6.35-22; 2.6.35-23; 2.6.35-24). i tried to remove the oldest kernel 2.6.35-22 through synaptic manager, but it says that the kernel is not installed on the system. in fact, all the kernels i have on my system were shown as not installed. when i right-click it highlights only ‘mark for installation’. so i tried to remove it from the terminal using the command:

it showed the grub2 without the deleted kernel. then i restarted, but it was still there. then i logged into the latest kernel (2.6.35-24) and typed:

sudo update-grub

it showed everything including the deleted kernel. then i typed:

sudo update-grub2

and it now showed everything, including the deleted kernel. i thought it was a problem with grub showing deleted entries, so i tried to boot the deleted kernel (2.6.35-22) and surprisingly it booted very well, no hicks or slows. i rebooted into the latest kernel and then tried to re-run the kernel delete command via the terminal, but it said that the old kernel (2.6.35-22) is not installed.

i don’t know what’s wrong. how do i delete the 2.6.35-22 kernel and update my grub/grub 2?

pls help me!!!

thanks.

***besides, my grub is stil GRUB 1.xx version. but pls how come i still have / can run grub and grub2 on my system? and is also can update both grubs? thanks

[...] from Setting Up Ubuntu Server on Linode Top Posts How to Install Google Earth in Ubuntu 10.04 Remove Ubuntu Kernels You Don’t Need Create a Bootable USB Drive the Easy Way in Ubuntu 8.10 Open RAR Archives in Ubuntu How to Install [...]

[...] which kernel I installed my latest VirtualBox with. The first thing I did tonight was to purge all my unused kernels, and start with a fresh install of VirtualBox in the last kernel standing. To get get my monitors [...]