Tombuntu

Remove Ubuntu Kernels You Don't Need

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.

Click the apply button on the tool bar to complete the changes.

Your computer and Grub menu should now be free of old kernels.

Archived Comments

Ap

I usually also keep the second-to-last, just in case the first one breaks.

jaywee

Greatï¼?

tux_82

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.

Rayfen Windspear

The way linux is built it would destroy the system to do a “restore” unless they made some massive changes to specifically accommodate for it… all of which would suck incredibly.

Danzano

Android is built on linux ubuntu is built on linux android has recovery sooooo………….???

Anonymous

So Great! I just needs to remove the kernels I installed wrongly.

Norm

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!

bubble

I also uninstall linux-headers-xx (of course not the current one)

MOS38

thanx it was useful …
thank U sooooOOooooo much …
wish u the best …

Hoang

Oh I’ve just met the same problem with Norm! I’ll try it then. Thank you all guys.

Shrinath

Thank you for the article..

Its just that many ubuntu newbies know something about synaptic but they dont know that even kernels are managed by it :) Thanks!!!

jardenp

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.

Thanks!

Josh in Indianapolis

Wang

thanks so much much neater without all those old kernels cluttering up my GRUB menu

Terry Wang

After upgrade, just use apt-get autoremove to remove the old kernel packages.

Manually delete the initrd.img.old/vmlinuz.old in /, as well as in /boot, edit grub menu.

Make sure u do it carefully, do not delete the current kernel:)

grisha

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?

mortgage

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.

GAJ

When trying to uninstall an older kernel, the synaptic package manager ask also permission to remove other modules, for instance when uninstalling:

linux-image-2.6.24-19-generic

the following modules need to be removed too:

linux-restricted-modules-2.6.24-19-generic
linux-ubuntu-modules-2.6.24-19-generic

Is it safe to remove these, or will this mess up my system?

macnet

thanks a lot for this tutorial! was very helpful! regards from Portugal

Anonymous

an unusually succint and understandable “HOW TO” TA

dubski

it’s a good idea but make sure to keep at least one old kernel. sometimes things go bad and the only way to fix it is to load the old kernel.

Leon

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)

Nikolaus

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.

-=Slyfox=-

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.

Schwager

thank you for the clear + good informations, it works !

I prefer Synaptic then doing it “by hand” like
apt-get remove linux-headers-2.6.20-15 linux-headers-2.6.20-15-generic linux-image-2.6.20-15-generic –purge

greetings from France

commandline

command line would be great. Anything in linux should be done in the command line.

ontadimanamana

nice
its work
thank you :)

f0rth3w1n6

it works yeeeeahhhh thank you

Juan Manuel

This is by far the best guide I’ve found!!!
Most of all guides around just tell you how to erase the grub entries but this one explains how to uninstall the old kernels…
Thanks a lot!!!

Dangger

Thanks. It worked like a charm in Ubuntu 9.04

jmm

How to uninstall a new kernel?

Suddenly I couldn’t boot from the usual kernel in Ubuntu 9.04 64-bit and am using an older one. I would like to reinstall the newer one.

In Synaptic I see the following packages installed:

linux-headers-2.6.28-15
linux-headers-2.6.28-15-generic
linux-image-2.6.28-15-generic
linux-restricted-modules-2.6.28-15-generic

linux-image-2.6.28-11-generic
linux-restricted-modules-2.6.28-11-generic

I have noticed that the older packages have no dependencies. But they are the ones in use. However, if I try to uninstall all the newer version packages, Synaptic will also uninstall:

linux-headers
linux-headers-generic
linux-image-generic
linux-restricted-modules-generic
dkms

How should I reintall the new kernel in order to make it work? Which 2.6.28-15 packages do I have to remove and how?

Thanks so much,

jmm

jmm

I actually just enabled the jaunty-proposed repository and updated the newer kernel.

I would have liked to update to the 2.6.30 kernel but I am too much of a newbie to know the benefits / risks.

Prodigit

Thank you for the easy patch, it helps me save space on my 4GB USB flash device!

One question though:

Does GRUB get updated automatically or does it need to be edited manually?
(And what about those of us who don’t run Grub on a system booting up a Linux kernel)?

Lurchman

“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)”

Yeah, you might as well. Frees up a whole bunch of disk space :)

Sava

Doesn’t sudo apt-get autoremove get rid of them even if the entry remains in grub’s menu ?

Henry Hertz Hobbit

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):

$ cd /etc/grub.d
$ sudo chmod 644 20_memtes*
$ sudo update-grub

Where I got it from:

https://help.ubuntu.com/community/Grub2

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.

Eric

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.

sridharan

Thanks a lot. I was able to remove the older version from the grub menu after following above procedure
Sridharan.

sj

worked like a charm on ubuntu 9.10 - appreciate the help

jonny rocket

epic fail. now it won’t boot. gotta re-load. lost ALL my data.

Andrew

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.

satyen

thanks buddy ,i was looking for the same

satyen

i am installing all but the latest ones of linux-image in synaptic manager .totally it requires 2.2 gb.tell me if this is updating the kernel.

Mark

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

2 apt-get autoremove won’t necessarily remove older kernels

3 for the message

uninstalling:

linux-image-<kernel number>-generic

the following modules need to be removed too:

linux-restricted-modules-<kernel number>-generic
linux-ubuntu-modules-<kernel number>-generic

go ahead, it’s perfectly normal, no cause for concern, you won’t need the kernel modules for that kernel once you’ve no longer got that particular kernel

try to avoid uninstalling however
linux-headers
linux-headers-generic
linux-image-generic
linux-restricted-modules-generic
dkms

when synaptic/apt-get is saying that, it’s a sign you’ve been checking the most recent kernel, that’s a no-no! :-)

Best

Mark

veldt35

I personally use Ubuntu Tweak to remove all the old kernels without any problems. :-)

arw

One command:
sudo aptitude purge ~ilinux-image-.*\(\!`uname -r`\)

Masroor Gilani

Thanks so much, it worked like a charm, fully automatic,cheers

wtftw

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.

Julio C.

Simple and turned half a Gb back to my sistem :p

Thanks

Duy

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.

undifined

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.

Rishy

thank you so much..keep up the gud work

obi

help!!!!

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:

sudo apt-get remove linux-headers-2.6.20-15 linux-headers-2.6.20-15-generic linux-image-2.6.20-15-generic –purge

it processes and show that it has been deleted. then i typed:

sudo update-grub2

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

adam l

dpkg -l linux-* | awk ‘/^ii/{ print $2}’ | grep -v -e `uname -r | cut -f1,2 -d”-”` | grep -e [0-9] | xargs sudo apt-get -y remove

Ben

Thank you very much for this. Very helpful; that grub menu was getting way too long.

li

Thank you, this article was very helpful! Can free up so much space now :D

JoeInLA

Thanks, Tom.

This worked perfectly. I was looking for an automated way to do this.

anonimo

Thx men, it works

person

Make sure to run sudo update-grub at the end!

d4

And here is on small script to only keep the currently running kernel and the two most recent ones:

dpkg -l | grep ^ii | grep “linux-image-[0-9]” | awk -F’ ‘ ‘{ print $2 }’ | grep -v `uname -r` | sed ‘$d’ | sed ‘$d’ | sed ’s/linux-image//’ | xargs -i echo “linux-image{} linux-headers{}” | xargs sudo aptitude purge

Chakra schmockra

I am having trouble. I looked up the kernels and they can only be installed and not uninstalled. WHat am i doing wrong?

Namraj

Thanks for the article.I didnt know even boot is controlled by synaptic manager.

Respond via email