GRUB 2 bootloader - Full tutorial

Discussion in 'all things UNIX' started by Mrkvonic, Dec 4, 2009.

Thread Status:
Not open for further replies.
  1. Mrkvonic

    Mrkvonic Linux Systems Expert

    Joined:
    May 9, 2005
    Posts:
    10,223
    Hello all,

    Hear, hear! The long awaited GRUB 2 ultra-guide is ready!

    I have carefully prepared and written an extensive tutorial about how to setup and configure GRUB 2 (version 2, the next generation) bootloader with multiple operating systems, including GRUB legacy and GRUB 2 mix, dual-boot and triple-boot real-life testcases covering Ubuntu, Kubuntu, openSUSE, Mandriva, and Windows 7, upgrading from GRUB legacy to GRUB 2, menu customization, and basic and intermediate troubleshooting.

    You will love this, I promise you!

    http://www.dedoimedo.com/computers/grub-2.html


    Cheers,
    Mrk
     
  2. andb

    andb Registered Member

    Joined:
    Aug 21, 2008
    Posts:
    51
    You are right, i did!
     
  3. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    Brilliant tutorial which needs more studying by me for sure.
    One thing that baffles me is that you received error 13 when chainloading from
    Suse with legacy grub (in MBR) to Ubuntu with grub2 installed to the pbs.
    I have never had this error chainloading Ubuntu 9.10 (grub2) from Ubuntu 8.04 (legacy grub).
    Could it be due to having Ubuntu 9.10 on a separate drive - not just a separate partition ?
    Maybe it would work in your case if you use the --force command sudo grub-setup --force /dev/sda6
    for Ubuntu ?
    The core.img seems a better and neater solution.

    Another thing I don't understand. The 40_custom template file states that the first 2 lines must be:-
    #!/bin/sh
    exec tail -n +3 $0

    but yours start with #! /bin/sh -e
    I know that's right as I have seen it - but it's confusing.

    Lastly, what if one gets a kernel update to a custom entry OS - will the custom entry script(s) be
    also updated ?
    Anyway, thanks for the all in a nutshell yet comprehensive tutorial Mrk.:)
     
  4. Mrkvonic

    Mrkvonic Linux Systems Expert

    Joined:
    May 9, 2005
    Posts:
    10,223
    Answers:

    A separate drives implies a bootloader installed somewhere, I guess. If you installed grub legacy to mbr sda and grub2 to mbr sdb then you can use chainloading. But grub legacy does not recognize the format of the linux kernel used by ubuntu, so you need core.img.

    If you use 40_custom, then yes, mind the tail thingie, if you use your own scripts, no need for that.

    Custom entries won't be updated. This does not happen with grub legacy either. Give you my quadruple Ubuntu laptop as example. When I update the 2-4 OSs, I must edit the grub menu on 1st and change the kernel and initrd lines to references new once. Now, suse does this more elegantly and creates generic vmlinuz and initrd symlinks to latest installed kernel, so you don't have to do this, but it's a per distro thingie and no automatic update.

    I might add your questions to the tutorial ... :)

    Mrk
     
  5. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    Yes, I see re. custom entries. Thanks.
    I have no problems whatsoever chainloading 9.10 from grub legacy as explained above.
    Would you mind taking a quick look at my boot info to confirm ?

    View attachment RESULTS.txt
     
  6. lewmur

    lewmur Registered Member

    Joined:
    Dec 22, 2008
    Posts:
    332
    This was great work and is really appreciated. But it points out to me the fatal flaw of Grob2. It is a bloated solution to a problem that didn't exist. Legacy grub works fine, thank you.

    All grub2 does, IMHO is add a lot of trouble and confusion to a very sensitive problem. The first issue people wanting to experiment with Linux face is dual booting. Why make it more complicated than absolutely necessary?

    To me, grub2 is a very good example of something that completely ignored the KISS principle.
     
  7. Mrkvonic

    Mrkvonic Linux Systems Expert

    Joined:
    May 9, 2005
    Posts:
    10,223
    Ocky, yes your setup is good.
    Mrk
     
  8. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    Good, thanks - all is working well.
    BTW. Another thing I noticed is that when grub2 is updated the following warnings are shown:-
    "Attempting to install GRUB to a partition instead of the MBR. This is a BAD idea.
    Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and its use is discouraged.
    If you really want blocklists, use --force."

    So it seems that grub2 is 'uncomfortable' with being installed to a pbs (/).
    This warning didn't show on the initial install - only when grub2 is updated. It doesn't affect anything though - more like a scare tactic ?
     
  9. Mrkvonic

    Mrkvonic Linux Systems Expert

    Joined:
    May 9, 2005
    Posts:
    10,223
    Didn't notice this warning.
    What versions are you talking about? 1.97.x?
    That's why it's called ... beta.
    Mrk
     
  10. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    1.97 beta4.
    Actually, if I remember correctly, it only showed once when there was an update to grub-pc bootloader itself, and not when updating due to installing a theme or disabling os-prober or the timeout value. I have seen something like this mentioned also in the Ubuntu forums. Will keep an eye on it - see what happens going forward.
    Regards.
     
  11. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    There was an update today: grub-pc and grub common. Now 1.97 beta 4.1
    The message:
    "Attempting to install GRUB to a partition instead of the MBR. This is a BAD idea.
    Embedding is not possible. GRUB can only be installed in this setup by using blocklists. However, blocklists are UNRELIABLE and its use is discouraged.
    If you really want blocklists, use --force."

    Can be seen if one clicks on 'Details' during the installation when installing with Update
    Manager. ( You will also see it should you do an apt-get update if it finds updates to grub2 ).
    As mentioned before there are no detrimental effects or unpleasant shocks. :argh:
     
  12. wat0114

    wat0114 Guest

    Thank you for this Mrkvonic, but I had to give up only 1/4 of the way through. It is just far too complicated for me, having lost my focus in the sea of command lines that ensued. What grub 2 needs, perhaps, is an easy to use editing program like Vista/Win 7 EasyBCD.
     
  13. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    For sure, it takes an average joe like me quite a while to get my head around Grub2.
    One thing is really easy though -- Splashimages for the Grub2 menu.
    This is what I did...used the Lake mapourika image...

    sudo apt-get install grub2-splashimages

    You'll find your new splashimages in /usr/share/images/grub/

    gksudo gedit /etc/grub.d/05_debian_theme

    find line 16 or 17 and change the following code from:

    for i in {/boot/grub,/usr/share/images/desktop-base}/moreblue-orbit-grub.{png,tga} ; do

    to replace 'moreblue-orbit-grub' with the name of the splashimage of your choice:

    for i in {/boot/grub,/usr/share/images/grub}/Lake_mapourika_NZ.{png,tga} ; do

    NOTE: Be careful to keep the dot in the filename! eg: 'Windbuchencom.'

    update-grub
    _______________________________________________

    You can also visit Herman's Grub 1.97 page to see what the packaged images look like.

    PS. Install the nautilus-gksu package - then you will have 'Open as Administrator' in the
    right-click context menu. (Log-out then Log-in again to get it set in context menu)

    Edit: I also set the menu text colour to white and the highlight colour to red for easier readability ..

    # set the background if possible
    if ${use_bg} ; then
    prepare_grub_to_access_device `${grub_probe} --target=device ${bg}`
    cat << EOF
    insmod ${reader}
    if background_image `make_system_path_relative_to_its_root ${bg}` ; then
    set color_normal=white/black
    set color_highlight=red/black
    else
    EOF
    fi
     
    Last edited: Dec 16, 2009
  14. wat0114

    wat0114 Guest

    Whoaa, needless to say my struggles will be greater than yours :eek: Thanks for the info, all the same. I think if I don't have to touch the grub 2, I simply will not ;) However, I've got the / & /Home partitions imaged and tested with successful restores so it does give me some reason to get adventurous. We'll see :)
     
  15. Mrkvonic

    Mrkvonic Linux Systems Expert

    Joined:
    May 9, 2005
    Posts:
    10,223
    You can always test in virtual machines ... safely and with no fear of damaging your host system.
    Mrk
     
  16. wat0114

    wat0114 Guest

    True enough and good suggestion but I had removed the linux VBox install because I'm happy with the way it's running on the real system, dual-boot with Win 7. Besides, after having another perusal of the tutorial, I've decided it's way more than I care to brave atm. Maybe sometime later I'll go for it :)
     
  17. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    I would like to make a bootable Grub2 CD so that I can get to the command line if the need arises.
    Which method should I use to create the live cd .iso ?

    This way, I presume from within the OS ( U. Karmic in my case) ...

    grub-mkrescue --overlay=/boot/grub GRUB2RESCUE.iso
    (from http://members.iinet.net/~herman546/p20/GRUB2 Bash Commands.html#GRUB2_CD-ROM)

    Or from a Live CD of the same distro (U. Karmic) ...

    grub-mkrescue --image-type=cdrom /tmp/grub-rescue.iso
    wodim /tmp/grub-rescue.iso


    I was always under the impression that creating a bootable .iso had to be done using a live cd ?
    ( I know about SGD but would like to do it ... 'my way' ) :argh:

    PS. What does the overlay option mean in layman's terms ?

    Found more info on Google so should be OK.

     
    Last edited: Jan 15, 2010
  18. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    grub-mkrescue --overlay=/boot/grub GRUB2RESCUE.iso

    That worked well, I had no problem booting from the Grub2CD.

    Grub2CD iso.png

    One question. Say one or more of the grub files in /boot/grub/ of the installed OS are bad - could I simply boot from my Grub2CD and then extract and copy all the files from the Grub2CD.iso in my /home to /boot/grub/ ? Sounds too easy imho.
     
  19. Mrkvonic

    Mrkvonic Linux Systems Expert

    Joined:
    May 9, 2005
    Posts:
    10,223
    Yes, that should work.
    Mrk
     
  20. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    Good to know, thanks a lot.
     
  21. wat0114

    wat0114 Guest

    That looks nifty. I have a Supergrub 2 iso burned to disk but never took the opportunity to try it and not even sure how it works. It should offer the same benefit, I assume, of fixing grub 2 issues?
     
  22. Ocky

    Ocky Registered Member

    Joined:
    May 6, 2006
    Posts:
    2,713
    Location:
    George, S.Africa
    Typing configfile /grub.cfg at the grub prompt is very nice. You get the Grub2 menu just like you configured it i.e. with background image, timeout etc.
    Must say I am pleased I tried this.

    @wat0114 I think someone with SGD experience will be more qualified to advise on your question. I have not yet used it.
     
Thread Status:
Not open for further replies.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.