SEARCH

How-To Geek

Clean Up Ubuntu Grub Boot Menu After Upgrades

One of the things in Ubuntu that has always driven me crazy is the addition of new items into the grub menu without removing the old entries that likely don’t even work anymore. I’m sure most experienced Ubuntu users already know how to do this, but here’s the method anyway.

Important: If you’re using a newer version of Ubuntu with grub 2 (like Ubuntu 9.10 or later), you’ll need to read about how to clean up the New boot menu instead.

I just installed this box recently, and then did an upgrade…. already there are 7 items in the menu.

image

To remove these entries, we’ll need to edit the file /boot/grub/menu.lst. You can do this by using Alt+F2 and then typing in the following command:

gksu gedit /boot/grub/menu.lst

image

Now that we’ve got the file open, scroll down to the bottom of the file where it says “End Default Options”, and you’ll find all the menu entries for the various kernels in here. You can just select and delete the ones you don’t want.

image

Save the file, and then the next time you boot up you’ll see a much nicer set of options.

image

I’m guessing it would also be prudent to clean up the other unused kernel files that are sitting out there… I’m sure there’s some automated tool to do that, but I’ve not taken the time to figure it out yet.

Lowell Heddings, better known online as the How-To Geek, spends all his free time bringing you fresh geekery on a daily basis. You can follow him on if you'd like.

  • Published 09/6/07

Comments (50)

  1. dlb

    No need to delete those lines to simplify the GRUB menu. The easier way to keep only newest lines is to open the menu.lst (gksu gedit /boot/grub/menu.lst), find “#howmany=all” and change it to “#howmany=1″. Then run “sudo update-grub” to update changes. Next time, only newest kernel lines will be shown.

  2. Ben

    Been a while since I’ve done this, but IIRC shouldn’t you also check what the default option is and adjust if necessary after cleaning? I.E. if the default was item #3 and you delete #1 and #2, it needs to be changed to default to the new item #1. This only applies if you delete items above your default choice. Am I remembering this correctly? I could easily be thinking of something else…

  3. The Geek

    dlb: That’s great, I wasn’t aware of that!

    If you’ve changed the default choice, then you’d probably have to correct it at this point… of course, if you’ve changed the default choice, you already know what you are doing and wouldn’t be reading this =)

  4. dlb

    If u have more than one OS in your PC (example: Ubuntu and Windows), the tip that i mentioned above is the best way to update GRUB automatically. You dont need to delete any lines (and change the “default” value also) after every time your Ubuntu box is updated :)

  5. Grenadier

    If you want to remove old unused kernel versions, the easiest way is to just use Synaptic–search for the version number and just remove every package with it. However, it’s probably a good idea to keep at least the latest old version in addition to the newest one–newer versions can break things.

  6. Lozza

    That’s a fantastic tip, dlb. My grub menu was taking up most of the screen and I’d no idea how to get rid of it. Thanks!

  7. Andy Goss

    If you put your chainloader items first, and set default to the first kernel title, you don’t need to change the default every time you get a new kernel or change #howmany

  8. Ted Kotz

    A better solution would be to just use your package manager of choice to remove the linux-image- packages that corresponds to the no longer used kernels. I would leave at least 2 kernel versions so you can go back to an older version for maintance/recovery purposes if needed.

  9. hussaibi

    I would not suggest getting rid of them.

    I once tried to change my install from ubuntu gutsy to debian lenny through apt-get,
    which is a horrible idea. There was a conflict involving init that I didn’t fully understand, causing my kernal to panic and consequently be unable to mount the file system. So, long story short, without those entries, I never would have been able to recover my computer. Luckily I still had an internet connection (after editing /etc/network/interfaces) and access to root on my feisty recovery mode (which I did not have on my gutsy recovery mode or normal feisty entry, because they both panicked as well).

    So, yeah, the extras might be annoying, But they might just save you fom a bad “upgrade”, or atleast, the recovery ones will.

  10. heiner

    hello,

    after deleting some entries, like windows and opensuse, i can’t find these entries anymore. but once in a while
    i like to run windows, can anyone give me a tip, how to restore the entry? i’m a complete newbie…

  11. Andy Goss

    Heiner, there is probably an example for you in the commented part at the start of your menu.lst. You need something like this:

    title Windows 95/98/NT/2000
    root (hd0,0)
    makeactive
    chainloader +1

    This assumes your Windows is on the first drive. You don’t say what distro you are using, but if you have Debian, Ubuntu etc, there will be a line:

    ### BEGIN AUTOMAGIC KERNELS LIST

    Put your Windows entry before it, and change the default line (near the top) to 1 – assuming that you want your Linux to be the default. GRUB numbering begins with 0.

  12. Dave Dalton

    Tried your advice above, and it worked very well. Recently installed Ubuntu on my Acer Aspire laptop (dual-booting with XP home that the laptop came with), and being a newbie to Ubuntu, I much appreciated the advice. Just finished reading first Ubuntu book (Keir Thomas), and while book is thorough, it did not cover some practical problems like the ever-expanding GRUB menu. Thanks again.

  13. Keelaf

    The normal way (i.e. without editing config. files):

    1. In a console, run “uname -sr” to find which kernel you use.
    2. Then remove every “linux-image-XX” and “linux-headers-XX” packages that do NOT correspond to the kernel you are using. You can do this with “adept”, “aptitude” or “apt-get” (if you need help to use those tools, you can go to the ubuntu documentation and search how-to remove packages).
    3. In a console, run “sudo update-grub”.

    Done.

  14. zeekoe

    @keelaf:
    i just removed those packages using synaptic package manager, in my opinion the easiest way for newbies like me (no console) to install and remove any software in ubuntu (specially because synaptic checks for dependencies).
    AND i even noticed that during the removal of the old linux kernels, GRUB was automatically updated!

  15. Marsellos

    Ive done it not thru the terminal, though going to the terminal is a lil bet high level one.
    What I did is that I use Add/Remove program, add for installation the QGRUBEditor and the Startup Manager. Play with the QGRUBEditor. nway, you can return anytime to the default bootloader thru the StartUp Manager when things get wrong.

  16. Nick

    I’m agreeing with zeekoe here. The easiest way is to open Synaptic, search for the kernel version string numbers (i.e. “2.6.22-14″, etc. as they appear in the GRUB menu) that are not the ones you select in the GRUB menu when you boot up, and select the “image” entry for “Mark for Removal”. Synaptic handles correct dependency removal (and it lists them for you before removing anything), it edits the GRUB menu automatically removing the correct entries, and frees up about 120-150MB of space for each kernel image it removes.
    No command line interaction, no partial removals leaving annoying hard-to-find dependency leftovers, and no doing one piece manually while not addressing any remaining pieces that are directly related to it.

  17. Gavin

    Hello!
    Your tip helped me ALOT. I had like 15 different choices for one Ubuntu installation!
    Now, I have Ubuntu, Recovery Mode, Memtest, and Vista. It has helped alot.

    Love your site!

    -Gavin

  18. T3KH34D

    Those entries are actual kernels you still have installed on your machine. There have been several instances where I have upgraded my kernel and have it break modules and drivers that I had installed, particularly sound and video drivers. I would suggest keeping at the very least the most recent kernel, and the last working kernel you had before the image upgrade. You can use aptitude, apt-get or synaptic to remove the previous kernel images which you can easily find in synaptic if you do a search for linux-image you will see your previous kernels listed as well as any modules you have downloaded. Just removing these entries from GRUB doesn’t remove them from your machine, they are just no longer on the boot menu.

  19. Ken

    Just use “startup manager” – -

    Open synaptic, search “startup manager”, install, then launch. This will allow you to configure GRUB

  20. gescape

    Giving this kind of tips wouldn’t you begin with “Please copy the original file, just in case…” and how to quickly and easily restore it?
    Someone may cut to much and cry… ;)
    Rgds,
    Ges

  21. Joe Farruggio

    I am running a dual boot system (Window XP home edition and ubuntu ver 7) when i try to install ver 8.0 of ubuntu,i go thru the complete installation but when i reboot grub just hangs. The same thing occurs when i try to install ver 8.10. I tried super grub and it cannot find any files nor can it load itself. Hoever with ubuntu version 7, everything works fine.

    PS i also tried loading grub from the installation disk and it will not load.

  22. Andy Goss

    Joe. It has been a while since I had any GRUB trouble. I suggest you look at some Ubuntu-specific forums, such as LinuxQuestions.org and JustLinux, as well as the GRUB home page – http://www.gnu.org/software/grub/ and any Ubuntu documentation and wikis.

    In my files I have the following, but do check the GRUB manual first so you understand what you are doing:

    1) Boot with your Installation, Rescue CD, or GRUB floppy.

    If using a GRUB floppy, jump to step 6.

    2) Type “linux rescue” at the prompt (if required).

    3) Answer the questions about keyboard and language.

    4) # chroot /mnt/sysimage

    5) # grub

    6) Set GRUB’s root device to the partition containing the boot directory:

    grub> root (hd1,0) // the controlling grub.conf is to be
    // the one on the second drive, first partiton

    7) To put GRUB onto the MBR of the first drive, where the BIOS will expect to find it:

    grub> setup (hd0)

    If you want to put GRUB into the boot sector of a partition instead of putting it in the MBR,
    specify the partition into which you want to install GRUB, eg:

    grub> setup (hd1,0)

    which will put it on the first partition of the second drive.

    8) grub> quit

    9) # reboot

    * The controlling GRUB info is in
    /boot/grub/grub.conf
    of, in the case above, second drive first partition

    It is a few years since I dual booted an MS OS, but I assume you will then have to edit your menu.lst to chainload XP, as in the example I gave several entries ago. And do note that there is a space between “+” and “1″ in the chainloader command.

  23. einchi

    Nice Dlb, it’s working well, thanxs:))

  24. sukiminna

    instead of editing the grub/menu.lst i think there is another way to clean it..

    maybe try this in terminal:

    sudo apt-get autoremove

    &

    sudo apt-get autoclean

  25. cojon

    Please do not misunderstand. This is a VERY friendly message, and I am happy as a clam in soft mud. I just need help and I am not finding it easily. I hope you can help me–and others.

    Thanks for all the tips and help, but as an extreme new Ubuntu user (forth day!), I find something I can’t understand every time I make an attempt to locate help. Everyone (so far) assumes *SOME* knowledge, and either steps are left out or there are undefined, and very unknown words or there are apparently sensitive parts shown but not explained. As example, I went to our town library and I very accidentally met four young men who were also looking for an Ubuntu “How-to” book. They felt exactly the same. Worse, each of us had been to the Ubuntu forum and none of us could figure out how to even leave a message asking for help on the forum. It seems everyone can tell you how to make partitions in Ubuntu, but no one tells you how to install Ubuntu into those partitions so the swap file winds up in one, /home in another, / where it belongs,and if there are more, I don’t know what they are. Someone just told me that you click on that tiny little four pixel triangle to go into a forum. With zero experience, how do you know? That’s pretty small and I have never seen one before.

    I’m not at all complaining, and I sincerely appreciate every gem of knowledge I get, but could I ask two things? First, is there a place I can go to find actual beginner help? and secondly, please remember when you provide something for a beginner, please work really hard to be complete. I have no idea how to do anything mentioned in this site, nor in any of the responses. Too new, and it’s all Greek to me.

    My thanks to each of you for all you did to assist (really!) and in time I’m sure I will get it, but WOW is it tough at first. The guys in the library, finding there was no book, were flatly disgusted. They had tried to install Ubuntu for three days and couldn’t get it working. They assured me they would NEVER look at Ubuntu again. Hard to blame them when it’s all so foreign–except to those who understand it. I brought a new member to my sailing club who felt like that afterwards and never came again. It happens a lot. People don’t have much patience these days.

    I’m sure Ubuntu silently looses many new followers because of this. I wrote to the people who write the Ubuntu help, and they will not respond or are just taking their time. In my tiny east Texas town, the cows outnumber computers 10 to 1, and the five of us may be the only ones even looking at Ubuntu. Now we are one. Please help me encourage polite and complete assistance for beginning Ubuntu users so this great and FREE underdog Ubuntu can gather the teeth to bite Microsoft in the butt!

    Thanks again, and keep it coming…

  26. Andy Goss

    Start at http://www.ubuntu.com/support – then buy a book. You are unlikely to ever find an up to date computer book in a library. I don’t use Ubuntu myself, so I can’t suggest a particular one, but I would avoid the “… for Dummies/Idiots” type as they take a long time to say rather little. Look for Ubuntu in Amazon, the book that comes first is the “Official Ubuntu Book”, the reviews look positive. And it is quite cheap. I have found the “Linux Pocket Reference” published by O’Reilly, to be a very useful addition to the main book for my distro.

    Don’t bother about the partitions, let the Ubuntu installer sort that out. As a beginner accept all the defaults. The Ubuntu people have taken pains to simplify the installation as much as possible. Last time I installed it for my daughter there was very little for me to do. Do read up about the installation first so you know what to expect, you will find a detailed account on the Documentation site – linked from ubuntu.com/support. There are quite a lot of steps to get there so here is the URL – https://help.ubuntu.com/community/GraphicalInstall

    As for forums, try http://ubuntuforums.org/ – you will find under Main Categories on the right “Installation & Upgrades, where you may find answers to your questions. NOTE – to ask a question you need to register (upper left corner).

    If you need more software than comes with the CD or DVD, don’t do it the Windows way, read up on how to do it the Linux way, which is different, easier, and better.

    If you are confused, just ask here, but you should start a new “thread” rather than use this one which is about a different problem.

  27. Andy Goss

    Cojon, try this link: http://www.zdnet.com.au/video/play/22173870

    And do register for a forum or four, people are keen to help. These are comments on an article, go to the forum – see the blue bar at the top of the page – to ask questions.

  28. Mehboob Sadicote

    Thanks for the tip, i had previously removed a couple of old headers using sudo aptitude purge linux linux-headers-, but they continued to be displayed in the boot options. This completes the purge, i suppose.

  29. Anton

    Cool!

  30. Lisa the traveller

    cojon is right. This is still a big bag wolf for Ubuntu, and the only problem I have seen so far in the new install.

    If the partition/setup swap/formatting thing could get more user friendly and make recommendations and such, Ubuntu installation could be done by anyone.

    I had to search all over the internet to figure out what the best way to set up the partitions was, and in the end I had to guess!!!

    It should give you an example that would be most usable and ask you if that’s okay. You should NOT have to search all over the internet if you don’t know what the right size for your partitions would be best.
    IMHO

  31. Andy Goss

    Lisa. There is no simple answer to partitioning. It depends on what you will be using your computer for. There is plenty of advice available, it took me about two minutes to find this: https://help.ubuntu.com/9.04/installation-guide/i386/partitioning.html which tells you all you need to know.

    Easiest is to let the installer do it the way it wants to, which will probably, I have not installed Ubuntu for a couple of versions, be a single partition. For most purposes there is nothing wrong with a single partition.

    There can be advantages to multiple partitions, but it depends on what you are doing. I decided on a separate /home partition so that in an emergency, such as I had two days ago, I can re-install the operating system, Debian in this instance, without losing my data or personal configurations.

    I allow 8 GB for /, swap according to memory size, the rest is /home. With a plain Ubuntu desktop you could probably drop the / partition down to 6 GB or even 4, but unless space is a problem allow more space than is strictly required. The link above goes into detail about splitting it down further if you must, but home desktop installs really don’t need that.

  32. maverick

    dlb:
    Many thanks! It’s working perfectly fine!

  33. Beesblaas

    I agree with T3KH34D, Zeekoe, Nick, Ted Kotz, Grenadier, etc:

    The BETTER WAY of cleaning your Grub menu is to use Synaptic Package Manager.
    Then you actually remove the unused kernels AND you clean up your boot menu automatically.
    What you are suggesting here only takes them out of the boot display list.

    1) Note down all the Image versions when you boot.
    2) System > Administration > Synaptic Package Manager
    3) Type in search box: linux-image-
    You will get a list with some entries like: linux-image-2.6.xx-xx-
    4) Pick from the list all those old images, i.e. “mark for complete removal”
    except the latest two, the most current one and, (in case you need to fall back) the one before that. 5) Apply.
    This will properly remove the old kernels and automatically clean your boot menu.

  34. Jason

    Three things.

    1) Considering the sensitivity of config files to things like a missing semicolon or such, using Synaptic instead of manual editing is the wiser choice. However, knowing where to go looking in case Synaptic is broken is definitely also a very wise thing. To that end…

    2) The file is no longer /boot/grub/menu.lst I’m not sure when it moved since I’ve recently returned to ubuntu and the last version I used was gutsy… But I’m running karmic and the important info bits are now located in /boot/grub/grub.cfg, toward the end of the text file.

    3) I didn’t see it mentioned about clearing out the header files for the now-banished kernel images.

  35. pete25r

    I’ve got one for y’all.
    Ok so before I came to this How To I was plinking around the internet trying to figure out how to tidy up my grub. Well I tried to edit the files the the update-grub command uses to actually make the menu.lst and all that. No joy on tidying grub.
    It did find a failed install of UbuntuStudio though! It appeared on next boot under my Win XP boot entry (bottom on list). it was listed as “Ubuntu 9.10″ no kernel name or anything, kinda weirded me out until I booted it out curiosity.
    The UbuntuStudio install failed for some silly reason, don’t remember, was like whatever and slapped in ye ole Ubuntu USB bootdisk.

    Thanks for all the info guys. I like the idea of using synaptic to remove all but the last working kernel. Sounds like the way ahead for all the light-weights like me. The console doesn’t scare me it just pains me to type up all those directories and whatnot, like when you have to give a command like sudo gedit /etc/grub.d/20_filename
    get’s old quick if your not all that familiar with the directory structure and filenames. Good way to learn how the system is structured though.

  36. Davey Yzermans

    Can you also change the auto load delay? It’s currently 8 sec. and I’d like to make it shorter.

  37. Craig Westlake

    As Jason said the menu.lst is now an empty file. It has been replaced with /boot/grub/grub.cfg whaich is a read-only file and says not to edit it.

    So now I’m back to square one with not veing able to clear my Grub Menu. Any ideas?

  38. Arul J

    I agree menu.lst has been replaced with grub.cfg. Only the computer/system “root” has access to edit or modify that file. So you may have to login as root and change the security settings on “grub.cfg” using “chmod” command and edit the file followed by replacing the original security settings again with “chmod” command and restart the system to have the change in place. Hope this helps!. If you have questions you may write to me

  39. Paul

    OP: Can you edit the original post to reflect that menu.lst is only applicable on 9.04 and earlier? GRUB2 is now the default and…

    …DO NOT EDIT THE grub.cfg FILE on Ubuntu versions after 9.04!!!

    Here is a link to explain what you can do…https://wiki.ubuntu.com/Grub2

    BTW, using Synaptic IS the best, easiest, and safest way.

  40. pw

    @Paul

    True but they didn’t took the dignity to explain how to do it nor make a program to change it easy. This is one of those small things that make me feel frustrated with Ubuntu, well no big deal I guess.

  41. Nishandh M

    thanx, it helped so much. extensive documentation, So much confidence-generating for new comers like me..Thankyou

  42. harish

    thanks alot for the post it was very help full

  43. Fred

    Wouldn’t the easiest, and cleanest option be:

    Open Synaptic Package manager. (Under system, administration)
    select the older kernel, and remove it.(On left side, look in all, on right side, under quick search, type in the kernel number, and search. Unselect that version, Apply. The older kernel will be removed, and on the next boot, it will also be gone from Grub.

  44. Alan

    I deleted the current kernel by accident and now in the grub menu i only get the windows options (i have a dual boot win7 and lucid lynx) how can i recover it??

  45. suraj

    Fred, Your method works. Thanks in deed.

    Hi Alan, Just install Lucid Lynx again, use upgrade option when re-installing, your old stuff will be there.

  46. suraj

    Hi Alan, apologies, overlooked the date of your post. you may moved on in 3 months time.

  47. ghingz

    Hi.. i need help..

    I install my ubuntu inside the windows vista os (dual boot).. the ubuntu folder is in C: drive..
    I accidentally deleted all my ubuntu kernels using apt-get by issuing this command:
    apt-get remove –purge 2.6.x-x*
    now my when i booted up the computer.. the kernels are all gone..
    Is there a way to install the ubuntu kernel? and recover my ubuntu os?
    i tried to boot in grub but i dont know what to do.. its my first time to see the grub promt actually..

    thanks for advance!!

  48. ghingz

    Hi saruj, how to reinstall my lucid? i have the same case with alan.. i tried to install again the ubuntu 10.04 on windows vista but it requires me to uninstall first the old version..

  49. Angel24

    just remove its from terminal if u want remove its n change kernel versions with new ones.,
    no need edit grub list.,

  50. the correct method

    As mentioned using the package manager is the correct method.

    I use this script to automate it:

    TO_REMOVE=$(dpkg –list | grep linux-image |grep “ii” | perl -p -e ‘s/ii ([^\s]*) .*/$1/g’ |grep -P “[0-9]” |grep -v $(uname -sr|perl -p -e ‘s/.* //g’) |sort|head -n -1|perl -p -e ‘s/\n/ /g’);
    aptitude remove $TO_REMOVE;

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!