MakeTechEasier
  • Home
  •  
  • About
  •  
  • Archives
  •  
  • Jobs
  •  
  • Advertise
  •  
  • Contact Us
  • Windows
  • Linux
  • Mac
  • Internet
  • WordPress
  • iPhone
  • Android
  • All Categories
    • Android RSS
    • Firefox RSS
    • Gaming RSS
    • Google RSS
    • google chrome RSS
    • Internet RSS
    • iPhone/iPod Touch RSS
    • Linux RSS
    • Mac RSS
    • Mobile RSS
    • OpenOffice RSS
    • PC Hardware RSS
    • Review RSS
    • Roundup RSS
    • Windows RSS
    • Windows Mobile RSS
    • WordPress RSS
    • WordPress Plugins RSS
  • rss icon
  • email icon
  • facebook icon
  • twitter icon

Mastering Grub 2 The Easy Way

Posted by: Joshua Price on November 19th, 2009
  • 26 Comments
  • Share

grub2-smallIf you’re running Linux, there’s a good chance your distro of choice uses Grub as the default bootloader. Grub has served well for many years, but it’s beginning to show its age. As with all software, it doesn’t take long before the latest-and-greatest becomes old-and-haggard. Features have been piling up in Grub without much thought going into revamping the core program. Eventually, this lead to a messy patchwork that no one really wanted to maintain. At this point, Grub2 was born. It’s a complete rewrite from the ground up using a completely redesigned structure. This new Grub gives us powerful features like conditional statements (if/then, etc), intelligent upgrades, and some greatly improved graphics.

Getting Grub2

Currently, if you want to use Grub2, your best bet is to run Ubuntu 9.10 (Karmic Koala). If you just want to toy around and see what it can do without risking your system, I’d suggest running it inside a virtual machine as described here, but of course with Ubuntu 9.10.

menu.lst/grub.cfg

If you’ve messed with the original Grub (now called Grub legacy), you doubtless know all about menu.lst. That was the file where Grub legacy stored pretty much everything. In Grub2, the closest equivalent is grub.cfg, also located in /boot/grub. One of the most important differences, however, is that you should not edit the grub.cfg file directly. Some of you may be thinking “Ha! Warnings like that are for n00bs!”. Well the reason for this rule is not because the developers don’t think you’re l33t enough, it’s because that file is auto-generated by Grub2 and will be overwritten without warning as a result of things like kernel upgrades.

grub2-grubcfg

Any time the update-grub command is run, Grub2 will read its various config files and use their contents to generate grub.cfg. These files are dealt with individually below.

/etc/default/grub

Many of Grub’s options that used to be in menu.lst are now here. This includes things like whether or not to display the Grub menu, and how long to wait before timeout. This screenshot is the default config in Ubuntu 9.10, and is set to hide the Grub menu, disable “recovery mode” options, and instruct the kernel to include a splash screen.

grub2-etcgrub

By the way, to force Grub 2 to show the menu on boot just hold down the Shift key while Grub is starting.

/etc/grub.d/

This is where things really begin to differ from Grub legacy. Where you’d normally enter all your boot options in the menu.lst file, Grub 2 takes a very different approach. The /etc/grub.d/ directory contains individual files, each representing a option for the boot menu. The following shows the files contained in the default install.

grub2-etcgrubd

While it’s certainly a lot different than Grub legacy, you may notice something familiar about that folder. It’s set up in a way very similar to the standard Linux startup system, SysV Init. Each of the files shown is a shell script that executes in order. Order is determined by the numbers at the start of each filename, so the script in 00_header will always run before, say, 05_debian_theme.

/etc/grub.d/40_custom

Chances are, if you need to edit your boot menu, this is the file you’re looking for. This is where you add your custom entries to the menu. Since this is the last numbered file in the grub.d directory (as explained in the section above), any entries you place in this file will show up at the end of the boot menu.

By default, the 40_custom file is mostly empty. In this example, I’ve added a new menu entry.

grub2-40custom

Splash Images

You can easily download the Grub 2 splash pack in Ubuntu with:

sudo apt-get install grub2-splashimages

When it’s done, all the images will be stores as TGA files in /usr/share/images/grub/.

grub2-splashpreview

The file that specifies what splash image to use on boot is the 05_debian_theme file we saw earlier. So to set our new custom splash, we want to open /etc/grub.d/05_debian_theme as root in whatever text editor you prefer. Look for a line similar to the highlighted one in the example below,

grub2-changesplash

And change the filename to whichever splash image you prefer. Make certain the path points to the /usr/share/images/grub/ directory. Some older versions default to /usr/share/images/desktop-base/ and that’s not what we want.

Applying changes

As you may remember from the beginning of this guide, the grub.cfg file is auto-generated from the other config files we’ve covered. When you’ve made changes to those files, you’ve got to tell Grub to read them and pull together a new config file. To do that, simply run the following command as root:

update-grub

Once it’s complete, reboot your computer (or virtual machine) to see the results. Don’t forget to hold Shift while booting, if your menu is still set to Hidden.

grub2-large


Josh Price is a Linux professional and contributing writer to MakeTechEasier.com

Tags: bootloader, grub, grub2, karmic
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Share and Enjoy!

  • Rss feed
  • StumbleUpon It!
  • Del.icio.us
  • reddit

Related Posts

  • How To Restore Grub In Ubuntu
  • How To Create And Install Your Own GRUB Splash Image
  • Solving the “Can’t boot from Ubuntu 9.10 LiveCD, Showing Black Screen” Issue
  • How To Create And Install Your Own Usplash Theme In Ubuntu
  • Tweak Your Ubuntu The Easy Way

Popular Posts

  • Turn Your Ubuntu Hardy to Mac OSX Leopard 498 comment(s)
  • Turn Your Ubuntu Intrepid Into Mac OSX Leopard 311 comment(s)
  • 28 Coolest Firefox About:Config Tricks 122 comment(s)
  • How To Boot And Install Windows 7 From USB Flash Drive 122 comment(s)
  • Best 101 Free Computer Software For Your Daily Use 101 comment(s)

Enjoyed the article? Subscribe to Make Tech Easier today to get your daily updates of technology tutorials, tips and tricks.

Enter your email:

5 pingbacks/trackbacks (Click to open)

  • Links 20/11/2009: EVO Game Console is Out, Firefox 3.6 Beta 3 | Boycott Novell
  • Destillat KW48-2009 | duetsch.info - GNU/Linux, Open Source, Softwareentwicklung, Selbstmanagement, Vim ...
  • How To: Reinstall GRUB2 | Naman Zone
  • LINUX ??? ?????? – ??????? ?????? » ????????? Grub 2
  • Multiboot USB Stick | PMT's Blog
[Click to close]

26 Responses

  • neb says:
    November 19, 2009 at 10:08 am

    Nice explanation! I was recently frustrated with the new Grub2 package. Maybe now I’ll go tinkering to see if I can bend it to my will.

    Reply
  • Steve says:
    November 20, 2009 at 8:41 am

    Suppose on your dual boot you foolishly set timeout to zero, thinking that is an infinite setting, not zero. In the days of legacy Grub, you just booted up your live install disk, edited menu.1st, changing timeout=0 to timeout=10 or whatever and rebooted. Problem solved!

    Now, plastered all over the grub.cfg file are dire warnings not to edit that file. You cannot run your installed copy of startupmanager from the live CD, nor can you install it. What to do?

    I just boldly and foolishly edited grub.cfg anyway, changing timeout=0 to timeout=10. It worked fine. Then after Ubuntu returned, I ran startupmanager to set to 10 and get all the auxiliary files in agreement. Without tools to fix bonehead moves like mine, Grub2 IS NOT an improvement in this regard.

    Reply
    • Joshua Price says:
      November 20, 2009 at 2:04 pm

      Your method was fine, except you wanted to edit /etc/default/grub, not grub.cfg. Everything in grub.cfg is pulled from other files.

      In your case, the only difference needed was that you needed to edit /etc/default/grub, not menu.lst.

      Reply
      • neb says:
        November 20, 2009 at 3:44 pm

        … except that Steve had to edit the actual grub configuration from another OS (to recover from a previous grub configuration failure). Editing /etc/default/grub wouldn’t help, since he was not able to run the update script in the target OS. So, he had to directly edit the grub startup files (then he could reboot, re-apply his changes to /etc/default/grub, run the update script, then be back to normal).

        Right?

        Having to edit configuration then run some other script to “build” the “real” configuration is annoying.

        Reply
        • Joshua Price says:
          November 20, 2009 at 4:14 pm

          from livecd, it’d be something like:

          chroot /dev/hda1
          nano /etc/default/grub
          update-grub

          Reply
        • gus3 says:
          November 20, 2009 at 8:01 pm

          @Joshua Price:

          You can only hope your “chroot/nano/update-grub” sequence will work. Even with identical architecture distros, I’ve encountered chroot’d environments where libraries won’t link, device files are missing (or remapped), or filesystem features available on updated kernels conflict with older kernel versions.

          Please, actually try something on a test system before dispensing this kind of advice.

          Reply
  • A Lurker says:
    November 22, 2009 at 11:21 am

    Will this grub auto-boot a degraded RAID array? Or will it still ask me if I want to do so? Well, yea, I suppose if I went to the trouble of mirroring two disks in case one should fail out there in that distant data center, I *do* want it to boot. That’s why I’m mirroring, isn’t it?

    Oh, but wait, I can put a pretty picture on the boot screen! Sheesh, this is a non-starter. I’m sticking with Lilo.

    Reply
  • Jungle says:
    November 22, 2009 at 1:06 pm

    Thanks for your article which is most useful

    I have some suggestions/criticism in relation to Grub2 development. This is
    based on my experience using Grub 2 with Ubuntu/Kubuntu – I think it’s similar
    with outer distros.

    1. On a Dual boot system which I share with a non Linux user (windows), I
    discovered that Grub automatically added a Windows restore partition as a first
    of two Windows entries – leading to potential wiping of system by non
    technical user

    2. Every time Grub gets updated, all older installed kernels get added as boot
    options. I think the older kernels and the memory test options should be
    relegated to a ‘More options’ menu. Normally they are not used.

    3. In light of the above, I think that the user should be given some graphical
    UI or popup when Grub is being installed or updated – so that the user can
    (de)select appropriate boot options (e.g. check-boxes). Hints could be
    provided (e.g. “Note: This partition is probably a Windows restore partition).

    Thanks again for the article – I previously just edited
    ‘grub.cfg’ – without any problems ;) – I will take another look – and I hope
    there is some options so that I don’t have to remove Restore partitions and
    unused kernels every update)

    23.

    Reply
  • mario says:
    November 22, 2009 at 1:25 pm

    For me, grub2 didn’t work. Appearantly “grub-probe” can’t deal with LUKS encrypted partitions or /etc/crypttab, or maybe it’s the btrfs partition that disturbs it that badly.
    However, the automatic boot file configuration doesn’t seem all too well thought out. The additional programming language features in the boot loader would better be spent elsewhere.

    Reply
  • me says:
    November 22, 2009 at 4:47 pm

    Can Grub2 boot from CD/DVD drive? System Commander was able to do this task 10 years ago. Grub-legacy cannot do that. What about Grub2? I prefer to disable DVD boot in BIOS and have an option in my GRUB menu to boot from DVD drive when needed.

    Reply
  • Sikku says:
    November 23, 2009 at 1:57 am

    Grub2 showed lots of promise to boot live CD iso images directly from Hard disk, the same way as it would boot from CD/DVD drive. But for me it was not possible even after doing lots of experiments with grub2. I never edited grub.cfg instead I always edited the 40_custom file and updated grub. Has anybody tried doing it and was successful in it??? Please help me out… Thanx..

    Reply
  • David Smith says:
    November 23, 2009 at 5:20 am

    Grub 2 is far from ready for general distribution, and certainly is unsuitable being put in the latest Ubuntu release as the default. I found this out the hard way because I went ahead and installed karmic on my multi-boot pc. Luckily, because it got the configuration spectacularly wrong, including writing itself to the mbr of the wrong hdd, the only thing it messed up was the new karmic installation — it was very difficult to chainload from my existing grub legacy mbr bootloader (sometimes it would boot, often it wouldn’t).

    I finally got karmic to boot reliably by booting it directly from grub legacy and bypassing grub 2 (which is still installed, but harmlessly doing nothing).

    The advice on how to “restore” grub 2 is a horrible kludge, for power users only. Everything about grub 2, from functions to appearance shows it to be in a very, very unfinished state.

    GNU/Linux has come far enough along that users need not be subjected to this sort of thing anymore.

    Reply
  • TaQ says:
    November 23, 2009 at 10:27 am

    Thanks for your post!

    I have a question. There was a bug on Ubuntu 9.04 where we needed to insert some configs on the menu.lst file. The bug is described here (https://bugs.launchpad.net/ubuntu/+bug/334249) and we needed to use something like this:

    kernel /boot/vmlinuz-2.6.28-13-generic
    root=UUID=aa6577a8-fec3-4628-b0db-90e400355d15 ro vga=791 i8042.reset
    i8042.nomux i8042.nopnp i8042.noloop

    where i8042.reset i8042.nomux i8042.nopnp i8042.noloop are the options who must be inserted on the end of the line to make the book works fine again. With Grub2, where we can append/insert/edit those options?

    Best regards,

    Reply
  • David Efflandt says:
    December 2, 2009 at 8:27 am

    Put additional boot options in /etc/default/grub. The first is default extra options for normal kernels, and the second is anything added for (recovery) entries:

    GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash”
    GRUB_CMDLINE_LINUX=”"

    I had to remove the “splash” option from 64-bit Ubuntu 9.10 on my desktop, because splash crashes grub2 with my DVI connected older 1280×720 HDTV Ready LCD even if I specifically set GRUB_GFXMODE=640×480 (1 second flashing cursor, then endless black screen with no disk access or anything). Although, the HDTV handles PC video modes up to 1280×1024 and regular defaults worked fine when VGA connected.

    Reply
  • Neil says:
    December 5, 2009 at 5:21 pm

    Fully agree with David Smith. I currently have one Windows 7 entry at the bottom (I want it at the top), two entries for memtest, recovery and normal kernels, and only want one for each (these came after I ran Synaptic Update Manager and it updated the Linux kernels).

    I have no idea how to move Windows to the top, or how to remove the duplicate entries.

    Hate to say this, but sometimes, Windows does it better. Their startup menu is easy to edit (as was Grub the first) using 3rd party apps. Maybe someone will come up with something for grub2.

    Reply
    • Chuong says:
      January 15, 2010 at 12:01 am

      If you want to change the order of boot entry, just change the number in front of the files in grub.d/
      I wanted win7 first so I change 30_os-prober to 07_win7 for example

      Reply
  • srhegde says:
    December 12, 2009 at 8:06 am

    I got grub2 installed (upgraded on my karmic). Though I see TIMEOUT=10 in one of the files, the grub does not automatically boot with the DEFAULT=0 OS. I will have to press “Enter” to start the booting.

    Any idea what I may have to change in order to get this working?

    Reply
  • dale m says:
    December 12, 2009 at 11:23 am

    i did this how to but i am haveing problems hiding the othere intres in my menu i need help thanx .

    Reply
  • Bob says:
    December 12, 2009 at 11:55 am

    In grub legacy I could easily edit /boot/grub/menu.lst.

    I have two PC’s with XP and several Linux OS’s including Puppy where I must manually enter the entry.

    On Grub 2 ( installed from Ubuntu 9.10 or Mint 8 [Ubuntu-based] ) I need to edit, delete and add certain OS entries to what was easily placed or removed from ~/menu.lst.

    What should I do?

    —
    Bob

    Reply
  • Lio says:
    December 14, 2009 at 8:31 pm

    Ubuntu is starting to remind me of windows where it “improves” things just to make it more difficult for the user. Grub 2 is a case in point.

    Reply
  • Al Nonymous says:
    January 20, 2010 at 11:42 pm

    Anyone here remember “New Coke”?

    Grub2 and KDE4 are Linux’s “New Coke”.

    Reply
Cancel reply

Leave a Comment




Comment

Please Note: Comments maybe under moderation after you submit your comments so there is no need to resubmit your comment again

write for MTE

Latest Posts

  • OfficeMedium – A Social Collaboration Platform For The Small Business + Free Promotions
  • MakeTechEasier Is Now Hosted On KnownHost
  • KTorrent: KDE’s BitTorrent client
  • How to Create a Customized Toolbar for Your Browser
  • 13 Ways To Customize Ubuntu Netbook Remix For Better Usability

Our Writers

  • Damien Oh - Chief Editor
  • Sharninder - Geeky Ninja
  • Joshua Price
  • Tavis J. Hampton - Lantern Torch
  • Shevonne Polastre - FreeAgentWriter
  • Trevor Dobrygoski
  • Soumen Halder - Ampercent
  • Tanmay Ahmed - Tech-Tips-Geek
Make Tech Easier on Facebook
Jobs by SimplyHired
Job Widgets

Copyright

All the articles (including the text, images and tutorials) are properties of MakeTechEasier.

You cannot copy whole tutorials, either in English or translate to another language without our permission.

Write for us

Writing a tutorial or article for MakeTechEasier is a great way to get exposure and give back to the community.

Read More Details

Suggestions

We need your help to help us serve you better! This is YOUR site, so if you have suggestions/feedbacks on how we can improve it for you, please let us know! We do our best to make this place better!

Make a Suggestion

Navigation

  • Home
  • About Us
  • Advertise
  • Archives
  • Contact Us

Copyright © 2007-2010 Make Tech Easier | All Right Reserved.