Subscribe to 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.

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.

The Geek is the founder of How-To Geek and a geek enthusiast. This article was written on 09/6/07 and tagged with: Ubuntu

Daily Email Updates

You can get our how-to articles in your inbox each day for free. Just enter your name and email below:


Name:
Email:
Similar Articles Featured Wiki Articles
Latest Software Reviews Quick Linux Tips
Geek Arcade Popular Forum Threads

Comments (31)

  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.


Leave a Comment




Leave your friendly comment here.

If you have a computer help question, click here to leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Sponsored Links
Getting Started
About How-To Geek
What Is That Process?
svchost.exe
jusched.exe
dwm.exe
ctfmon.exe
wmpnetwk.exe
wmpnscfg.exe
rundll32.exe
wfcrun32.exe
Ipoint.exe
Itype.exe
Wfica32.exe
Mobsync.exe
Cmd.exe
Dpupdchk.exe Adobe_Updater.exe

Copyright © 2006-2009 HowToGeek.com. All Rights Reserved.