Subscribe to How-To Geek

Recommended: Click Here to Run a Free Scan for Common PC Errors   [Sponsored Link]

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 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. When he's not coming up with great how-to articles, he's probably writing at his personal blog. This article was written on 09/6/07 and tagged with: Ubuntu

Comments (14)

  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!


Leave a Comment




Leave your friendly comment here. If you have a computer help question, leave it on the forums instead.

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

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