-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
Questions Tags Tour Users Ask Question
Take the 2-minute tour
130
101
Every time I install a new Linux kernel, it gets left in the
grub config, making the boot menu longer eachtime.
I know I can manually search through the installed packages and
remove them.
Does Ubuntu provide any easier way to clean them up or keep them
from showing in the boot list?
share improve this question edited Jan 28 at 21:46
As well as removing the old kernels, uncomment this line in
/etc/default/grub if you want to get rid ofthe 'recovery' items in
the menu: #GRUB_DISABLE_LINUX_RECOVERY="true" poolie Nov 29 '10 at
6:04
136
+100
11.10 and newer versions of Ubuntu
GRUB2 and its display of all kernelsThe latest versions of Grub2
installed in Ubuntu automatically display the latest kernel and
hides the olderkernels that you may have installed.
If you do not see your grub - then remember to press Shift
whilst booting.
As you can see, only the latest kernel is displayed.
If you select the option shown (press Enter ) then all the old
kernels become visible and available to bootfrom.
Ask Ubuntu is a question and answer site for Ubuntu users and
developers. It's 100% free, no registration required.
How do I remove or hide old kernel versions, to clean up the
boot menu?
grub2 kernel
community wiki6 revs, 5 users 46%Hans
28 Answers ACTIVE OLDEST VOTES
event 2014 Community ModeratorElection ends in 2 days
asked 3 years agoviewed 109218 timesactive 26 days ago
Community Bulletin
Linked
6 Removing old kernel entriesin Grub
1 How to get rid of multiplelinux versions in grub bootmenu
2 How to remove old Linuxkernel modules tp_smapi?
19 How to remove kernels fromprevious release?
3 Why aren't old linux-imagesremoved when installing newkernel
updates?
10 How to clean previouskernels after update?
23 How to remove old kernelversions automatically?
25 How to remove the unwantedentries from the boot menu?
2 How do you clean up yourGRUB 2 boot menu?
0 How can I delete my olderversions of Ubuntu?
see more linked questions
sign up
log in
tour
help
add comment
Ubuntu Community Ask! Developer Design Discourse Hardware Shop
More
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
How to permanently delete ALL older kernels using the shellThis
will remove ALL versions but the current:
Or you can run this command as a cron job, if you want this done
automatically without confirmation:
However this is not wise, as you should ALWAYS have an old
kernel or two to fall back to (just in casethe new one doesn't work
with your system). At the very least, if you've just upgraded the
kernel, rebootbefore deleting the older versions. Read on for a
safer, more manual way.
How to permanently delete older kernelsFirst boot with the
latest available kernel.
There are a number of ways to delete old kernels. Personally, I
wouldn't touch Computer Janitor sincethis is acknowledged to break
your computer with its suggestions.
synaptic
An alternative is Synaptic ( sudo apt-get install synaptic )
search for linux-image, right-click a kernel and choose complete
removal and finally click the Applybutton to delete the kernel.
Repeat the search but this time for linux-header - you can
delete the associated headers for the kernelimage chosen
previously.
Synaptic though will not attempt to verify what you are trying
to remove... you could inadvertently deleteyour newest kernel - or
even delete all of your kernels via this tool leaving you with an
unbootableUbuntu!.
Remember to check which kernel you are using type:
The result would be similar to:
sudo apt-get remove --purge $(dpkg -l 'linux-*' | sed
'/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^
]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d')
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed
"s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^
]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
uname -r
Related
1 How to limit number ofkernels shown in boot menu?
5 How can I repair a newkernel version and omit thePrevious
Linux versionsfrom GRUB?
2 My kernel won't boot. Whatsteps should I take?
1 Default kernel is missing fromgrub 1 menu
1 How to uninstall old versionsof the kernel?
5 How to set default bootkernel in Ubuntu / Grub?
1 Old kernel in grub and /bootbut not uninstallable
6 Removing old kernel entriesin Grub
0 Unable to boot Ubuntu withnew Kernel but it works finewith old
kernel
0 Grub Menu opens on boot
Hot Network Questions
Why causality is preserved inspecial relativity?
Generate an understandablesentence
Spurious [?] vertical spaceintroduced by multicols
Program that creates largerversions of itself
(quine-variant)
How to encrypt more than 16bytes using AES?
Why is the mouse cursorslightly tilted and not straight?
Searching for closest entry in atable
Create a resizable symbol?
Moduli of flag varieties
Troubleshooting a Misfire
My wireless/WiFi connectiondoes not work. What can I do?
My colleague often shuts downmy machine through the LAN -how do
I prevent it?
Did I overstep my power asDM?
Can I mimic a C header thatredefines bool in C++?
Extracting the first 10 lines of afile to a string
I don't get this joke. Is it somekind of play on "water,
too?"
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
Remember the result and the number - make sure you don't delete
the corresponding image or header.
Ubuntu-tweak
IMHO, the best GUI tool is Ubuntu-Tweak
It is not available from the standard repositories. To install
you need to use the author's PPA:
Choose the options shown by the arrows.
Select both the headers and image with the same version
number.
It will not allow you to delete the current kernel you are
booted with since the current kernel is notdisplayed.
RecommendationMy recommendation is to keep at least two or
preferably three kernels including the latest. The reason forthe
recommendation is that you will have at least one/two other kernels
to boot with, if for what-everreason the latest kernel you are
unable to boot with or introducing a regressed capability such as
brokenwireless.
share improve this answer edited Jan 28 at 21:52
1 Removing old "linux-image*" packages using synaptic, worked
well with 10.04 too. (I mention it becausethe title suggests it may
only be for 11.10 and up) mivk May 17 '12 at 16:35
2 the -y switch at the end of the apt-get line is necessary,
otherwise apt-get just asks for confirmationand since the input is
a pipe, it just aborts. So it should end in: | xargs sudo apt-get
purge -y Josh Aug 26 '13 at 16:30
I added another way without xargs so a confirmation is asked on
the console before the kernels areremoved rubo77 Oct 30 '13 at
20:27
if you recommend to keep at least two kernels, you could have
written your script to do exactly that ;) (Iwas just looking for a
script that does that, but it seems that Ill have to write it
myself) trzsmkus Nov8 '13 at 12:56
I tried the approach using Ubuntu Tweak as being the most
appropriate (i.e., idiot-proof). Worked well. Bobble Dec 30 '13 at
17:02
sudo add-apt-repository ppa:tualatrix/ppasudo apt-get updatesudo
apt-get install ubuntu-tweak
community wiki5 revs, 5 users 79%fossfreedom
How can I handle versioningchanges when saving assets?
Why is the moment of inertiafor a hollow sphere higher thana
uniform sphere?
Do eunuchs have somethingdistinctive so people can tellthem
apart?
Why was the Treaty ofVersailles so harsh?
Why are salted hashes moresecure?
It was about weekend passes -menaing
How can I make this bruteforce faster?
A program that ends but neverends
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
show 1 more comment
52Open terminal and check your current kernel:
DO NOT REMOVE THIS KERNEL!
Next, type the command below to view/list all installed kernels
on your system.
Find all the kernels that lower than your current kernel. When
you know which kernel to remove, continuebelow to remove it. Run
the commands below to remove the kernel you selected.
Finally, run the commands below to update grub2
Reboot your system.
share improve this answer edited Jan 28 at 21:53
13 When doing this in 10.04 and 12.04, I found update-grub was
automatically run during the purgeprocess. aidan Jan 2 '13 at
0:45
17 bash's brace expansion can be used, e.g. sudo apt-get purge
linux-image-3.2.0-3{0..5}-generic (removes 30,31,..,35) ajo Mar 19
'13 at 9:04
It may seem obvious, but what this answer had that others did
not is "find all kernels that [sic] lower thatyour current kernel."
This is exactly the info I was looking for. Ziggy Oct 16 '13 at
9:55
34Removing Entries from Grub 2 Entries should be removed by
editing or removing files in the /etc/grub.dfolder. The
/boot/grub/grub.cfg file is read-only and should not normally
require editing.
Too Many Kernels?
If you are not sure of the kernel you are currently using, in a
terminal type uname -r.
Kernels removed via APT (Synaptic, "apt-get remove", etc.) will
automatically update grub.cfg and nouser action is required.
A great tool for removing kernels (and menu entries) is
Ubuntu-Tweak, a safe and easy-to-use GUIapp.
Install ubuntu tweak
Ubuntu-Tweak will be available under Applications > System
Tools.
Remove Older Kernel Entries
Select "Package Cleaner" on the left and "Clean Kernel" from the
right panel.
Press the "Unlock" button at the lower right, enter your
password.
Select from the displayed list the kernel images and headers you
wish to remove. The kernel in use isnot listed.
Press the "Cleanup" button at the lower right to remove the
selected kernel images and headers.
Remove Operating Systems from the Grub menu
uname -r
dpkg --list | grep linux-image
sudo apt-get purge linux-image-x.x.x.x-generic
sudo update-grub2
community wiki2 revs, 2 users 95%penreturn
add comment
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
Other Operating Systems which have been removed from the
computer will also be removed fromthe menu once "update-grub" is
run as root.
Menu items are placed on the Grub2 menu by scripts. If you don't
want other Operating Systems tobe entered in the menu, disable
/etc/grub.d/30_osprober
Run this command to stop the script from runningsudo chmod -x
/etc/grub.d/30_os-prober
DISABLE_30_OS-PROBER='true' in /etc/default/grub
Remove Memtest86+ from the Grub Menusudo chmod -x
/etc/grub.d/20_memtest86+
Run the update-grub command to allow the changes to be
incorporated in grub.cfg
Source
Note: After kernel updates a new entry is added to the GRUB
menu.You can remove the older one if youwant.However, most
experienced users will advise you to keep at least one spare entry
in case somethinggoes wrong with an upgrade and you need to boot an
older kernel version for troubleshooting purposes.
Alternate way to remove Kernel entries (prior to 10.04)
for GRUB not GRUB2
startupmanager You can find it under
System>>Administration>>
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
You see in the second screenshot you can select how many kernels
to show? I generally just keep it on 1,but when I get a kernel
upgrade I always change it to 2 before restarting so I can select
the older kernelif the new kernel has problems with my hardware.
Once I know the new kernel is working well I change itback to
1.
share improve this answer edited Mar 26 '12 at 9:00
2 Actually, startupmanager dint give me a window like this on
Ubuntu 10.04, instead it just gave a windowwith two tabs -> Boot
options and Advanced.. and in advanced it dint have the option to
limit the numberof kernels. So please update the answer for Ubuntu
10.04.(And thats why i down-voted this..) Sen Dec13 '10 at 5:12
any idea how "number of kernels to keep" can be defined on a
machine that has no GUI installed (server)? sylvainulg Mar 28 '13
at 9:24
29Purely commandline, this will remove all but the current and
second most current (via the "-2" in thehead command below):
share improve this answer edited Sep 17 '10 at 21:24
3 one-liner from there: 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 purge Dmitry Paskal Aug 5 '12at 19:31
community wikikarthick87
OLD=$(ls -tr /boot/vmlinuz-* | head -n -2 | cut -d- -f2- | \ awk
'"'"'{print "linux-image-" $0}'"'"' )if [ -n "$OLD" ]; then apt-get
-qy remove --purge $OLDfiapt-get -qy autoremove --purge
community wikiKees Cook
add comment
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
@DmitryPaskal, You should add this as a new answer. saji89 Mar
12 '13 at 10:26
2 @DmitryPaskal As always, don't just copy-paste these without
understanding them. On my machine thisone-liner also matches
linux-libc-dev:amd64 which shouldn't be removed. jamesadney Mar 12
'13at 20:19
@Kees Cook, shouldn't the awk argument only be surrounded by
single-quotes? If your intent is to prepend"linux-image-" to the
piped lines, this only seems to work if you use awk '{print
"linux-image-" $0}' . Mark Jun 12 '13 at 17:33
2310.04 GUI MethodComputer Janitor can clean up old kernels and
I believe is installed by default in Ubuntu (but notKubuntu).
GRUB 1, if you're using that, has an option in
/boot/grub/menu.lst to specify how many kernels itshould show at a
maximum. GRUB 2, as far as I can tell, does not.
share improve this answer edited Mar 26 '12 at 8:58
3 Computer Janitor should not be used - it is buggy and has now
been dropped as a default applicationin natty/oneiric/precise.
fossfreedom Feb 13 '12 at 16:04
1 Rather, install "Ubuntu Tweak" as described in another answer
(its own ppa), which has its own "computerjanitor" (not to be
confused with the "computer janitor" that temporarily was available
in older ubuntuversions) michael_n Feb 4 '13 at 2:10
15In order to remove older Linux image kernels, first boot in
the kernel you want to keep.
You can also check the kernel version using command uname -r so
that you don't remove the wrongone by mistake.
Now go to synaptic package manager and search for linux-image
and remove the older versionsexcept the one shown by upper command.
Generally I prefer to go with the latest one.
Now when you restart you'll see a more clean grub menu.
share improve this answer edited Mar 3 '11 at 13:10
This is probably the most basic method that will for users who
have installs w/o Computer Janitor. BroamSep 17 '10 at 21:34
1 From Ubuntu 11.04 the grub menu only shows the current kernel
by default, older kernels are hidden in the'Previous kernels' menu.
This method will still work for cleaning out the older ones. Andy
May 16 '11 at16:03
15To figure out what kernels and headers are installed use
You can then remove them one by one or together, just make sure
to keep the most recent.
There are also some handy commands and scripts to automate the
removal.
community wikimaco
community wikiAnurag
dpkg -l | grep linux-image
dpkg -l | grep linux-headers
add comment
add comment
add comment
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
http://ubuntuforums.org/showthread.php?t=1658648
The following claims to remove all unused kernels and
headers:
If you don't ever need old kernels, set that command to run as a
monthly cron job.
share improve this answer answered Oct 10 '11 at 14:25
14You can follow the Using the "unattended-upgrades" package
section of Automatic SecurityUpdates article on Ubuntu Wiki to
perform this.
You need to change the following line in
/etc/apt/apt.conf.d/50unattended-upgrades file;
with
to automatically remove old packages, including kernels.
Also remove or comment the line
in the "NeverAutoRemove" section of the file
/etc/apt/apt.conf.d/01autoremove.
share improve this answer edited Mar 1 '13 at 12:44
1 I did this but it was still collecting 3+ old kernels
consuming 100's of MBs. So I added apt-get autoremove to my daily
cron job that actually does the upgrades, since it doesn't always
go through built-in update-manager. Marcos Aug 24 '12 at 12:01
12My one-liner to remove old kernels (this also frees up disk
space)
Explanation (remember, | uses the output of the previous command
as the input to the next)
dpkg --list lists all installed packages
grep link-image looks for the installed linux images
awk '{ print $2 }' just outputs the 2nd column (which is the
package name)
sort puts the items in ascending order
sed -n '/'`uname -r`'/q;p' prints the lines before the current
kernel
xargs sudo apt-get -y purge purges the found kernels
Unwinding the sed invocation:
-n tells sed to be quiet
`uname -r` outputs the current installed kernel release - we
include it in backticks so that the
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed
"s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^
]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
community wikimikewhatever
//Unattended-Upgrade::Remove-Unused-Dependencies "false";
Unattended-Upgrade::Remove-Unused-Dependencies "true";
"^linux-image.*";
community wikisarimura
dpkg --list | grep linux-image | awk '{ print $2 }' | sort | sed
-n '/'`uname -r`'/q;p' | xargs sudo apt-get -y purge
add comment
add comment
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
output is includes as part of the command (you might also see
this as $(uname -r)
/something/q says stop when you match 'something' (in this case,
something is output of uname -r) - the / surround a regular
expression
p is print
the ; is the command separtor, so /something/q;p says quit when
you match something, else print
altogether, sed -n '/'`uname -r`'/q;p' is print the lines until
it matches with the current kernelname.
If you're paranoid (like me), you can make the last part xargs
echo sudo apt-get -y purge so thatthe command to purge the old
kernels is printed, then you can check that nothing unexpected is
includedbefore you run it.
Modified version to remove headers:
Note: the sed invocation is modified. "$(uname -r | sed
"s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")" extracts only the version (e.g.
"3.2.0-44") , without "-generic" or similar from uname -r
All-in-one version to remove images and headers (combines the
two versions above):
share improve this answer edited Aug 19 '13 at 9:17
Terminal power . Awesome combination and explain. NikTh Mar 28
'13 at 21:54
Thank you! This does not remove the kernel headers. I enhanced
your one-liner to remove the image andheaders of all kernels older
than the active one. dpkg --list | grep
'linux-headers\|linux-image' | awk '{ print $2 }' | sort -n | sed
-n '/'"$(uname -r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p' |
xargs sudo apt-get -y purge phiphi May 21 '13 at 11:53
@phiphi Note: your enhanced one-liner will only remove headers,
but not images (because when sorted, allthe headers come first, and
the sed cuts the list right before the first appearance of a
matching versionnumber) -- thus the 'linux-image' in your grep
statement is unnecessary. So, it is actually necessary to useboth
one-liner versions. Mark Jun 12 '13 at 16:04
Updated the answer to include the "all-in-one" one-liner which
combines both the image and header one-liners... Mark Jun 12 '13 at
16:12
Sorry, my oneliner doesn't work, you need two lines. if you make
a list of both linux-header and linux-imageand uninstall until a
current linux-header, you will not remove any linux-image. phiphi
Aug 19 '13 at 8:51
10You could install ubuntu-tweak and then Go to Applications
-> System tool -> ubuntu tweak and
dpkg --list | grep 'linux-image' | awk '{ print $2 }' | sort -n
| sed -n '/'"$(uname -r | sed
"s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p' | xargs sudo apt-get -y
purgedpkg --list | grep 'linux-headers' | awk '{ print $2 }' | sort
-n | sed -n '/'"$(uname -r | sed
"s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p' | xargs sudo apt-get -y
purge
echo $(dpkg --list | grep linux-image | awk '{ print $2 }' |
sort | sed -n '/'`uname -r`'/q;p') $(dpkg --list | grep
linux-headers | awk '{ print $2 }' | sort -n | sed -n '/'"$(uname
-r | sed "s/\([0-9.-]*\)-\([^0-9]\+\)/\1/")"'/q;p') | xargs sudo
apt-get -y purge
community wikiDavid Kemp
add comment
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
click package cleaner and clean kernels. it does not show the
currently used kernel so you will always besafe.
share improve this answer answered Mar 3 '11 at 13:26
7You can uninstall the old kernels ( linux-image-... packages)
using Synaptic, and that will removethem from the boot menu. Take
care not to remove the running kernel (you can check its version
with uname -r ).
Bear in mind that having a one or two older versions can help
you troubleshoot, should something gowrong.
Alternatively, you can edit/remove the entries manually ( gksu
gedit /boot/grub/grub.cfg ), butthey will be re-generated when you
update to a newer kernel. If you are thinking about removing
recovery mode options - don't. They can come in handy if you break
something which prevents you
from booting.
Refer to this page.
share improve this answer edited Nov 29 '10 at 6:30
Grub2 now builds it's grub entry everytime a new kernel is
installed. with update-grub which will re-writeall those kernels.
Marco Ceppi Dec 12 '10 at 18:47
5Personally, I like using Synaptic . It makes me feel more
secure about what's going on. The only appI've used that has an
option to remove old kernels is Ubuntu Tweak.
How to remove the kernels you are not using:
Open UbuntuTweak
Click on 'Package Cleaner' under 'Applications' in the left-hand
pane
On the right side of the 'cleaning view' press 'Clean
Kernels'
Select all kernels - I think the one in use is not listed but
just in case check running uname -a in aterminal
community wikiAlaukik
community wikievgeny
add comment
add comment
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
share improve this answer edited Apr 8 '13 at 0:24
3The fastest/simpler way (Applicable at least since 12.04)
possible that already comes with Ubuntu is apt-get . Do the
following if you wish to remove all older kernel versions that are
not in use (Except
the previous one that you are no using. This is to make sure
that if the current kernel version fails insome way, you have a way
to go back to a previous state). Do the following:
sudo apt-get autoclean
This will eliminate any old files (Including kernel versions)
you may have. Note that if you have many oldversions, it will take
a while since it has to make sure that removing the kernel version
has no issues. Forme, removing the last 12 kernel versions took
about 2 minutes. You can also do the following:
sudo apt-get clean
Which will eliminate everything downloaded and stored in the
cache folder of apt. Lastly you have:
sudo apt-get autoremove
which would check for any unused packages and remove them if
necessary. This is great for thoselibraries and dependency packages
that are no longer needed byt any app installed.
share improve this answer answered Apr 8 '13 at 1:13
2ailurus has the feature of removing old kernels as well as
unused configurations. I personally remove itmanually from
synaptic. You can install ailurus from getdeb as well as ppa
share improve this answer answered Sep 17 '10 at 10:53
2An easy way to get rid of almost all obsolete packages,
packages no longer in any package list, along withobsolete kernels
is to do one of the following:
However, this will miss packages that are still recommended by
other packages, and the -R/--without-recommends argument does not
resolve this problem.
dselect after switching sort mode with 'o' will show all
obsolete packages including the ones aptitudemisses, but some
people don't like using it.
share improve this answer edited Apr 6 '13 at 3:03
1Next time, when removing old kernels open a Terminal and use
this command: sudo apt-get
autoremovelinux-headers-2.6.38-10-generic
You can use Synaptic to get the exact name of the kernel that
you intend to delete. Just open Synapticand search for
"linux-headers" and then select which kernel entry you want to
remove. The relevant entrywill be tagged with "-generic" at the
end.
community wikiAlan FL
community wikiLuis Alvarado
community wikisagarchalise
dpkg --purge $(aptitude search ?obsolete)
community wikiChris Cheney
add comment
add comment
add comment
add comment
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
To clear out any unused (left over) dependencies throughout the
system use this command by itself:sudo apt-get autoremove
share improve this answer answered Oct 10 '11 at 13:39
dependencies are removed but I still have these files in /boot
folder. Patryk Oct 10 '11 at 13:43
1here is a rough outline of what I did, careful as I am no
expert in linux, be sure you know what you aredoing and have backed
up any files you are modifying.
then find the entries you want to keep, we will highlight and
copy them
you'll see a list of files like 10_linux and 30_os-prober
this will stop form auto adding all the linux entries into the
grub boot menu.
open the custom boot menu file, then go back to grub.cfg (which
should still be open in gedit), and copythe entries you want to
keep... such as
paste them into 40_custom , and then save it.
makes it executable, then finally we update grub which will
change the grub.cfg file:
Now, BEWARE, if you update your kernel or OS, your boot menu
probably will not update... you'll have todo that manually. But
doing this procedure will let you customize the boot menu a bit
more, such asremove the kernel version and just put the ubuntu
name... i.e. Ubuntu Lucid 10.04, etc...
Hope someone finds this helpful, as it took me a while to figure
out... didn't see this solution anywhere...
share improve this answer edited Jan 8 '12 at 23:31
2 This answer seems like overkill. It's better to just remove
old kernels. Scott Severance Jan 8 '12 at 23:32
I had read that extra kernels may be useful in the event of
recovery situations. Also, this is a simple way toedit the text of
the boot entry. So rather than saying "Ubuntu, Linux kernel
x.x.xx-yy --text1 -text2 -t3 -t4 --t5 etc etc etc" (where the
--text entries just denote some options/parameters I don't
understand) you canchange it to "Ubuntu xx.yy" although I had a "{"
bracket I couldn't get rid of. Joe Jan 9 '12 at 22:35
community wikiChad--24216
gedit /boot/grub/grub.cfg
cd /etc/grub.dls
sudo chmod -x 10_linux
gksudo gedit 40_custom
menuentry "My Default Karmic" { set root=(hd0,1) search
--no-floppy --fs-uuid --set cb201140-52f8-4449-9a95-749b27b58ce8
linux /boot/vmlinuz-2.6.31-11-generic
root=UUID=cb201140-52f8-4449-9a95-749b27b58ce8 ro quiet splash
initrd /boot/initrd.img-2.6.31-11-generic}
sudo chmod 755 40_custom
sudo update-grub
community wikiJoe
add comment
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
I keep the immediate previous kernel around until I've verified
the the most current kernel works properly.If it works, it isn't
going to stop working. So, after I've verified the most recent
kernel (after a week or so),I have no reason to keep the old kernel
around. If it doesn't work, then I have the latest known-goodkernel
to fall back to. Actually, I'm currently running an old kernel due
to a showstopper bug in the currentkernels. But that doesn't change
my overall policy. You only need one known good kernel. Scott
Severance Jan 10 '12 at 5:14
1Install the synaptic package manager and go down to the filters
tab (I think filters, if not try all 5) andselect "local". This
will show you orphaned packages on your system, such as the
kernels. After youuninstall them, run update-grub . That command
updates the list of boot options for grub.
If this fails, you can always try apt-get remove
linux-image-version-generic .
share improve this answer edited May 29 '13 at 16:41
1The following string of commands will purge any installed linux
kernels except the currently running one(grep -v uname -r ) and the
lastest available kernel (dpkg -l | .... | tail -1):
I use this to keep desktop's boot volumes relatively clean, but
in a server situation you'd probably want toexpand the logic and
write some additional scripting to maintain a list of the last X
kernels the server hasbooted.
Something like a startup script that does:
and then use:
share improve this answer answered Jun 30 '13 at 18:37
0I disabled the 10_linux boot file and put custom entries in
40_custom (copied/pasted from boot.cfg). Thatway you can edit the
text of the entry carefully. Although updating your kernel may not
update your40_custom file, so you may have to beware of that.
Although it's easy to fix.
share improve this answer answered Jan 9 '12 at 22:39
0This is by far the best answer in my opinion:
http://tuxtweaks.com/2010/10/remove-old-kernels-in-ubuntu-with-one-command/
community wikiRelish
dpkg -l | grep -E linux-image-.*-generic | cut -d ' ' -f3 | grep
-v `dpkg -l | grep -E linux-image-.*-generic | cut -d ' ' -f3 |
tail -1` | grep -v `uname -r` | xargs apt-get -y purge
uname -r >> /root/bootedkernelscat /root/bootedkernels |
sort -u | tail -3 > /root/bootedkernels # Keep the last 3 booted
kernels
dpkg -l | grep -E linux-image-.*-generic | cut -d ' ' -f3 | grep
-vf /root/bootedkernels | grep -v `dpkg -l | grep -E
linux-image-.*-generic | cut -d ' ' -f3 | tail -1` | grep -v `uname
-r` | xargs apt-get -y purge
community wikiAlexander Thompson
community wikiJoe
add comment
add comment
add comment
add comment
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
Follows the last command on the site above:
share improve this answer answered May 21 '13 at 15:52
0To have a bit more control over which versions to keep,
explicitly select the ones you want to remove. Forinstance if you
want to remove kernel versions 3.2.0.[49-53], use a simple for
loop:
Adjust the list of kernel versions to fit.
share improve this answer answered Nov 8 '13 at 12:51
0Try this. Run it as root.
Save this script as, say ./keep-n-kernels.sh
Pass, as a command line argument, the number of most recent
kernels you want to preserve.
Sample usage :
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
purge
community wikiBrunoJCM
for k in 49 51 52 53 ; do aptitude remove --purge
linux-image-3.2.0-${k}-generic ; done
community wikiNeilNjae
#!/bin/bash
# pass n as a command line argument, and it will find all the
installed# kernels and keep only the n most recent ones =>
uninstall all older ones
# dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed
"s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^
]*\).*/\1/;/[0-9]/!d'# this command gives the list of all packages
EXCEPT for the latest kernel.# source :
https://help.ubuntu.com/community/Lubuntu/Documentation/RemoveOldKernels
n=$1
# find the installed kernel versions :# dpkg-query -W
-f='${Version}\n' 'linux-image-*' | grep . | sort -n# gives version
numbers, one in each line# dpkg-query -W -f='${Version}\n'
'linux-image-*' | grep . | sed 's/\...$//g' | grep -v '\...$'| sort
-u# gives only the ones that appear in linux-image
# suffix, e.g. -generic-pae# the kind of kernel you boot
intosuffix=$(uname -r | sed
's:^[0-9]\.[0-9]\.[0-9]\-[0-9]\{2\}::g')
command="apt-get purge "
for version in $(dpkg-query -W -f='${Version}\n' 'linux-image-*'
| grep . | sed 's/\...$//g' | grep -v '\...$'| sort -u | head -n
-${n})do command=${command}"^linux-image-${version}${suffix}
"done
$command
add comment
add comment
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
If you want [AND AT YOUR OWN RISK], you can add a -y (or a force
flag) to the apt-get command andmake it non-interactive.
share improve this answer answered Jan 28 at 20:47
-1Backup your GRUB configuration file which is in
/boot/grub/grub.cfg which we will need if somethinggoes wrong.
Open Terminal CTRL+ALT+T. You need to be the root. For that
:
Now we want to edit the file. For that:
You will get GEDIT window.
Now search for ### BEGIN /etc/grub.d/10_linux ###.
After that line you will see the items of your GRUB.
So if we want to remove Ubuntu, with Linux 2.6.32-30-generic
from GRUB, Remove the redhighlited line in the image.
You should have got the idea of removing items from GRUB.
After editing the file save it.
Do as you like but be careful not to remove other lines.
**
NOTE
:**
When kernel is updated the /boot/grub/grub.cfg is recreated. So
the older kernels will be visible again.You have to do this every
time you run the command update-grub and after updating the
kernel.
Source (my blog): How to remove a item from GRUB boot menu
share improve this answer edited Jan 30 '13 at 13:18
# ./keep-n-kernels.sh 4 # launch the apt-get command to remove
all but the 4 most recent kernels
community wikiSankalp
sudo -i
gedit /boot/grub/grub.cfg
community wikiSubin
add comment
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
2 Thanks for the edit. Ubuntu has used GRUB2 since 9.10, so it's
unlikely any solution that would work forany version since then
would fail for any other version. (Thus, if this works for 10.04,
it probably works forlater versions too.) Unfortunately, because
it's GRUB2, this will probably not work at all, or at leastnot for
very long. The file you're editing, /etc/grub/grub.cfg is
automatically recreated when update-grub runs--and it is run every
time there is a kernel update (and for some other updates).
Eliah Kagan Jan 30 '13 at 13:10
-1Based on a previous answer by David Kemp, the following script
will purge all headers and images exceptfor the last 2
versions.
share improve this answer edited Jun 12 '13 at 18:42
Any reason why this was downvoted? Did it not work for someone?
When copying/pasting make sure youaren't wrapping long-lines when
you paste. I have had no problems with it working. Mark Jan 24 at
20:56
-1will remove old kernels and keep the last three versions. This
works since at least ubuntu 13.04, butmaybe also since 12.04.
The following guide is for you if you want to keep more (or
less) than the last three versions, use anolder version of ubuntu,
or otherwise want to have more control over the process.
This is a pure command line solution.
First generate a list of all installed kernel versions except
the currently running kernel:
Alternatively generate a list of all installed kernel versions
except the last two:
#!/bin/sh# This script assumes that the installed linux-image
and linux-headers packages# share the same versions (i.e. if a
linux-image version number is installed,# the corresponding
linux-headers package will also be installed, and vice# versa.)
SECONDTOLASTVER=$(dpkg --list | grep linux-image | awk '{ print
$2 }' | sort -r -n | sed '/^[^0-9]\+$/d' | sed
's/^.*-\([0-9\.]\+-[0-9]\+\).*/\1/' | uniq | sed -n 2p)
# get a list of package names matching the argument passed to
the function, and# return only those package names which should be
removedget_pkgs_to_remove_matching () { if [ -n "$SECONDTOLASTVER"
]; then echo $(dpkg --list | grep $1 | awk '{ print $2 }' | sort |
sed -n '/'"$SECONDTOLASTVER"'/q;p') fi}
echo $(get_pkgs_to_remove_matching linux-image)
$(get_pkgs_to_remove_matching linux-headers) | xargs sudo apt-get
-y purge
community wikiMark
sudo apt-get --purge autoremove
dpkg-query -W -f='${Package}\n' | grep -f
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
Examine the list. Make sure the the kernel versions you want to
keep are not part of the list. Use thecommand uname -r to see the
version of the currently running kernel.
If you are happy with the results you can use apt-get to remove
the packages.
First a dry run (using the first generator as example):
Then a real run:
If you want to automate the process then add the --yes
parameter:
share improve this answer edited Jan 17 at 12:30
-2Here's the script I use to keep 2 kernel packages installed
(i.e. the current one and the previous one). Italso removes the
initrd-VERSION-generic.old-dkms files left around by DKMS, which
can fill-up a smallboot partition.
The script:
share improve this answer answered Jun 17 '13 at 18:26
-3in addition to the above answers you could try to remove the
kernel image + system.map + config filesmanually. grub looks for
those files in the /boot directory.
remove any files not related to the kernel version(s) you use.
if you are using only the latest version, let'ssay 3.2.0-25, it
should be safe to remove all 2.6.* and 3.0.* versions. so you type
ls -alF /boot/2.6. tosee what's there and remove those. same with
all the other versions except the one(s) you are using.
NB: when updating the kernel it may be good policy to keep the
version that previously worked best for
sudo apt-get --dry-run purge $( dpkg-query -W -f='${Package}\n'
| grep -f
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
about help badges blog chat data legal privacy policy jobs
advertising info mobile contact us feedback
TECHNOLOGY LIFE / ARTS CULTURE /RECREATION
SCIENCE OTHER
Stack Overflow
Server Fault
Super User
Web Applications
Ask Ubuntu
Programmers
Unix & Linux
Ask Different (Apple)
WordPress Answers
Geographic InformationSystems
Database Administrators
Drupal Answers
SharePoint
User Experience
Mathematica
Photography
Science Fiction & Fantasy
Seasoned Advice(cooking)
Home Improvement
more (13)
English Language &Usage
Skeptics
Mi Yodeya (Judaism)
Travel
Christianity
Mathematics
Cross Validated (stats)
Theoretical ComputerScience
Physics
MathOverflow
Stack Apps
Meta Stack Overflow
Area 51
Stack Overflow Careers
you
share improve this answer answered Jun 24 '12 at 11:01
2 This seems likely to break things, particularly when 3rd party
modules have been installed. leonardo Apr1 '13 at 15:24
Your Answer
By posting your answer, you agree to the privacy policy and
terms of service.
Not the answer you're looking for? Browse other questions tagged
orask your own question.
question feed
community wikireplier
grub2 kernel
add comment
Post as a guest
Name
Email
Sign up or log in
Sign up using Google
Sign up using Facebook
Sign up using Stack Exchange
-
grub2 - How do I remove or hide old kernel versions, to clean up
the boot menu? - Ask Ubuntu
http://askubuntu.com/questions/2793/how-do-i-remove-or-hide-old-kernel-versions-to-clean-up-the-boot-menu[24/2/2014
01:26:04]
Webmasters
Game Development
TeX - LaTeX
Electrical Engineering
Android Enthusiasts
Information Security
more (14)Arqade (gaming)
Bicycles
Role-playing Games
more (21)
more (7)
site design / logo 2014 stack exchange inc; user contributions
licensed under cc by-sa 3.0 with attribution requiredrev
2014.2.21.1389
Ubuntu and Canonical are registered trademarks of Canonical
Ltd.
askubuntu.comgrub2 - How do I remove or hide old kernel
versions, to clean up the boot menu? - Ask Ubuntu
Vhbi11cC10aGUtYm9vdC1tZW51AA==: form1: q:
Vhbi11cC10aGUtYm9vdC1tZW51AA==: form119: input1: post-text:
display-name: m-address: