Bienvenido! - Willkommen! - Welcome!

Bitácora Técnica de Tux&Cía., Santa Cruz de la Sierra, BO
Bitácora Central: Tux&Cía.
Bitácora de Información Avanzada: Tux&Cía.-Información
May the source be with you!

Sunday, November 6, 2011

Grub 2 Guide

    grub.org grub 1.99 manual
    SourceForge web page
    Grub 2 Guide « Linux notes on February 14th, 2010
    Tux Systems » Grub 2 Guide on May 9th, 2010
    The Grub 2 Guide « X-KERNEL on May 26th, 2010
    The Grub 2 Guide « Diep Huu Hoang's Blog on October 16th, 2010
    Restoring the grub 2
    cebaehren advice:
    Boot from the correspondent CD (Live or Installer)
    For fakeraid use disk mapper RAID (forget it in normal installations)
    Read the output of devices and choose the correct partition where you have the root and the device (hard disk) where you want to install the bootloader (grub 2)

    sudo /sbin/dmraid -ay 
    sudo fdisk -l

    sudo mkdir /media/sda5
    sudo mount /dev/sda5 /media/sda5
    sudo grub-install --root-directory=/media/sda5 /dev/sda
    
      or use (fakeraid)
      sudo mkdir /media/dm-0p7
      sudo mount /dev/dm-0p7 /media/dm-0p7
      sudo grub-install --root-directory=/media/dm-0p7 /dev/dm-0

      and at last, always
      sudo update-grub
      ========================= 
      Grub 1.99 Changes

      This post provides a brief introduction to Grub 1.99. It presents a few of the differences with earlier versions of Grub "2" - Grub 1.97~beta or Grub 1.98. The actual version of Grub 2 distributed with Ubuntu 11.04, Natty Narwhal, is Grub 1.99 RC1.
      Background:
      With the end of official support for Ubuntu 9.10, Karmic Koala, Grub 2 is now the default bootloader for the entire Ubuntu Desktop family.
      Grub 1.99's improvements are especially noteworthy for users booting non-EXT 2/3/4 filesystems. Video capabilities are improved, there are support enhancements for Zen, btrfs, EFI, DM-RAID, grub scripting, USB hotplugging and lots more. For a more complete list of what's new for Grub 1.99, see the release announcement from Vladimir Serbinenko. For detailed descriptions of Grub 1.99, see the GNU Grub 1.99 Manual.
      Submenus
      In order to reduce the GRUB menu entries visible on boot, Grub 1.99 will incorporate a submenu feature in the main OS section of the menu. Only the latest kernel (plus its recovery mode if enabled) will be visible. If additional kernels are available, a new entry on the main menu will appear: "Previous Linux versions". Access to these additional kernels is gained by highlighting and selecting this menu, at which time a second page will display.
      Users can still set an older kernel as the default, but the format of the GRUB_DEFAULT= setting in /etc/default/grub has changed. Please refer to the following thread for more details on the submenu feature.
      Grub 1.99 Submenus
      Settings & Command Changes
      1. Installation
        • Grub will be upgraded to 1.99RC1 during an online upgrade to Natty or with a clean installation.
        • grub-gfxpayload-lists is a new dependency for grub-pc (Grub 2). It is used to help the graphical handoff from Grub to the kernel.
        • Previous releases of Ubuntu will not be upgraded to 1.99RC1. If desired, the user could temporarily change the main repository to natty, install grub-common, grub-pc and grub-gfxpayload-lists, then return the repository to the installed release. Upgrade only the specified packages. Doing an update of all packages with a combination of natty and another release will likely break your system.
      2. --boot-directory= option when using grub-install, grub-set-default, or grub-reboot

        • NOTE to Forum Helpers! This change is bound to create a bit of confusion in cases where the user needs to repoint the MBR to the actual partition with the Grub files. For several years we have been using the "--root-directory" switch. While the old command/switch will still work, it might be useful when/if using the new switch this change is empahsized. When using the "--boot-directory" switch, don't forget that the specified path must also contain grub's parent folder (normally 'boot').
        • When using the grub-install, grub-set-default, or grub-reboot commands, the new '--boot-directory' option is used to specify the target folder DIR/grub; i.e. the folder into which the grub folder will be installed. If the switch is not used, /boot/grub is assumed.
        • The default folder is /boot/grub if not specified.
        • Examples:
          To install on a currently-running Ubuntu installation located on the sda drive:
          Code:
          sudo grub-install /dev/sda
        • To install from the LiveCD to an Ubuntu partition mounted on sda's /mnt:
          Assuming you have separate boot (sda2) and root (sda6) partitions!
          Code:    
          sudo mount /dev/sda6 /mnt/
          sudo mount /dev/sda2 /mnt/boot
          sudo grub-install --boot-directory=/mnt/boot /dev/sda
        • Grub will be placed in the sda MBR and point to /mnt/boot/grub
        • This command is equivalent to the former "sudo grub-install --root-directory=/mountpoint /dev/sda", which will still work and would place the grub folder in the same location (sda MBR and the mounted partition's /boot/grub folder.)
      =========================
      First read it all: Source
      GRUB 2 has three main parts:
      1. /etc/default/grub - the file containing GRUB 2 menu settings.
      2. /etc/grub.d/ - the directory containing GRUB 2 menu creating scripts.
      3. /boot/grub/grub.cfg - the GRUB 2 configuration file, not editable.
      update-grub command reads the /etc/grub.d directory and looks for executable scripts inside it. The scripts are read, in the order of their numbering, and written into the grub.cfg file, along with the menu settings read from the /etc/default/grub file.
      Boot entries come from several sources - the default that comes with the distribution, other operating systems probed on the connected disks and custom scripts written by the user, following a strict syntax. The scripts are written as shell (sh).
      You can add/remove entries by simply chmod-ing the scripts; no need to delete them. GRUB 2 can be reinstalled anytime you want, even while booted in the OS.

      =========================

      =========================

      Selected Problems and Bugs 
      meierfra has been busily building pages which detail how to solve many of the common problems users are experiencing with Grub 2. His SourceForge web page should be one of the first stops for those seeking answers to Grub 2 issues.
      No Menu On Initial Boot
      If you are already on the Ubuntu Desktop, run “sudo update-grub”. This may detect additional operating systems, which may allow the Grub menu to be displayed on the next boot. Otherwise:
      Open /etc/default/grub:
      Code:
      gksu /etc/default/grub
      Disable the “GRUB_HIDDEN_TIMEOUT=” line by placing a # symbol at the beginning of the line.
      Set “GRUB_TIMEOUT=” to a positive integer (number of seconds to display the menu before automatic selection) or “-1″ to wait for the user to press ENTER (no timeout). The entry will look like this:
      Quote:
      #GRUB_HIDDEN_TIMEOUT=0
      GRUB_HIDDEN_TIMEOUT_QUIET=true
      GRUB_TIMEOUT=”10
      Save the file, update grub (“sudo update-grub”) and reboot.
      External Drive Installs – bug/496435
      Installs of Ubuntu on external drives can cause problems as grub-install uses device names (e.g. sda, sdb) rather than UUIDs in certain circumstances. If connected to another machine when an update of grub-pc is made, the upgrade may be written to the incorrect device and make the computer unbootable.
      A workaround is posted on the bug link above.
      External Drive Installs and MBR – bug/414996
      When installing Ubuntu to a USB drive, the potential exists for GRUB 2 to write to the hard drive’s MBR or split the installation between the hard drive and the USB drive (rather than completely on the USB device). This can render the main drive unbootable.
      Workaround: During the final stages of the install there is an “Advanced” button which allows the user to select the install location.
      HP Machines Fails to Load Grub after Using Windows – Bug [URL="https://bugs.launchpad.net/ubuntu/+source/grub2/+bug/441941"]bug/441941/URL]
      After installing Grub 2 on a HP machine, the system boots normally until the first time it’s booted into Windows. On the next boot, the system hangs at “Grub loading”.
      Workaround: HP protection tools are rewriting to the MBR when Windows is run. The protecttools app must be removed/disabled. Refer to post #10 in the Bug Report.
      VGA Deprecated” Message on Boot
      Symptom: A blank screen appears with a message concerning VGA being deprecated after the menu item is selected (manually or by default). The message will be a variation of: “VGA=792 is deprecated. Use set GFX payload=1024x768x24, 1024×768 using the linux command instead.”
      The message probably is informing the user that there is a vga entry on either the “GRUB_CMDLINE_LINUX_DEFAULT=” or “GRUB_CMDLINE_LINUX=” line of /etc/default/grub. “Deprecated” means that there is a newer, preferred way to convey this instruction in GRUB 2. (Note the “vga=” method will still work, despite the message. It is advisory only.)
      In the example above, the line would probably look something like:
      Quote:
      GRUB_CMDLINE_LINUX_DEFAULT=quiet splash vga=792″
      GRUB_CMDLINE_LINUX=”"
      To conform to the desired format and eliminate the message, change the above lines in /etc/default/grub to look like the following, using the “vga” value, and translated value, found in your current default file:
      Quote:
      GRUB_GFXMODE=1024×768
      GRUB_CMDLINE_LINUX_DEFAULT=quiet splash”
      GRUB_CMDLINE_LINUX=”"
      Save the file and run “sudo update-grub” for the changes to be incorporated in the menu.
      There is a vga conversion table located at:  
      From the GRUB 2 command line, you can run “vbeinfo” to see resolutions supported by your system.
      File Not Found (From a Grub 2 prompt)
      Not to be confused with the Grub Legacy “File Not Found – Error 15″ (See next).
      When this message appears in Grub 2, it means that G2 cannot find one or more of the files required to accomplish the task. If this occurs, the user can use the “ls” command to find out what drives/partitions G2 sees. The output normally is something like (hd0) (hd0,1) (hd0,2) (hd0,5) (hd1) (hd0,1), etc. Remember the first drive (X) is “0″, the first partition (Y) is “1″. You can then inspect the contents, checking for the proper files with /boot, with “ls (hdX,Y)/boot”, for instance.
      Often in this case the user must reset “root” and/or “prefix”. You can see the current settings from the G2 command line with the command “set”. If you know the device/partition you want to boot, from the Grub 2 terminal run the following. You will get no feedback if there isn’t an error. You can check the results by running “set” again.
      Code:
      set root=(hdX,Y)                    # Example:  set root=(hd0,5)
      set prefix=(hdX,Y)/boot/grub        # Example for a normal Ubuntu install on sda1: set prefix=(hd0,1)/boot/grub
      error: no such device: 86d32ee3-aec6-490b-8dab-e5cfff9c7af9
      This error is the result of a failure of the GRUB 2 search function. There are various bugs associated with the search function. To boot into your system, highlight the OS you want to boot. Press “e” to edit the menuentry. Delete the entire “search …” line, then CTRL-x to boot.
      Once you have booted into the system, you will modify the /usr/lib/grub/grub-mkconfig_lib file in accordance with this link:
      File Not Found (Error 15)
      This error is the result of a GRUB 2 installation to /boot but a Master Boot Record ( MBR ) which still contains Grub legacy. This can happen if you don’t select your drive when running sudo update-from-grub-legacy. Shortly after starting this command the user will be asked to select the device (sda, sdb, etc). Highlight the drive and press the space bar to select it when presented with this screen. Failure to select a drive will result in an Error 15.
      To recover from this error, GRUB 2 must be reinstalled. Go to the community documentation File Not Found (Error 15) for instructions.
      If you find you need to remove the following lines manually to get Grub to boot properly:
      Quote:
      recordfail=1
      save_env recordfail
      Open /etc/grub.d/10_linux with admin rights:
      Code:
      gksu gedit /etc/grub.d/10_linux
      Look for this section and comment the lines in bold;
      Quote:
      linux_entry ()
      {
      menuentry “$1″ {
      recordfail=1
      save_env recordfail
      Change it to:
      Quote:
      - linux_entry ()
      {
      menuentry “$1″ {
      # recordfail=1
      # save_env recordfail
      Save the file, then run
      Code:
      sudo update-grub
      The two lines should no longer appear when you press E to view the selection in the Grub 2 menu. You will see a “save_env save_entry” line but this should not cause the failure if you successfully booted the previous time.
      Grub 2 Hangs 10-30 Seconds between Grub 2 Loading and Menu Display.
      This is a known bug that can be caused by GRUB 2 and /boot being loaded on different partitions. To fix the problem, run
      Code:
      sudo dpkg-reconfigure grub-pc
      Select to load Grub 2 on the same device as the /boot partition. In your system BIOS, change the drive to boot from first to the drive with the /boot partition.
      Wubi Installs within Windows Won’t Boot.
      This bug has been fixed in Ubuntu 10.04. For prior versions, the user is greeted with “Try (hd0,0) : NTFS5: ” This is a known bug as well as others that may cause Wubi boot failures. Refer to meierfra’s Boot_Problems:Wubi_9.10 page.
      Grub “error: out of disk” or “failed to boot default entries”.
      This error message is sometimes generated when Grub 2 cannot properly write to the file /boot/grub/grubenv. Refer to meierfra’s Boot_Problems:Write page. 
      ===============   ===========
      1. Introduction
        I’ve written this guide to present some basic information about Grub 2. It is meant for users who may be familiar with basic editing of the original Grub (Grub Legacy) menu.lst and wonder how it carries over to Grub 2. The actual version of Grub 2 used in Ubuntu 9.10, Karmic Koala is 1.97~beta4; 1.98 is the Ubuntu 10.04, Lucid Lynx version. In keeping with Ubuntu’s “stable release” philosophy, 1.97~beta4 will remain the official version in 9.10/Karmic and will not be updated to 1.98. In this guide, any reference to Grub 2 will refer to the 10.04 Lucid Lynx 1.98 version, with major differences noted. Grub 2 will be the default in Ubuntu 9.10, Karmic Koala but the plan is not to convert over previous Grub legacy installations to Grub 2.
        Official Announcement / Story
        StartUp-Manager supports Grub 2, but not all options are available. The two most-used items, however, are: setting the default kernel/OS and setting the menu timeout delay. There are plans for a StartUp-Manager 2 that works only for Grub 2 but it is still under development according to its creator. To view a guide on installing and running StartUpManager, view the StartUpManager community doc or the forum post on which it was based: http://ubuntuforums.org/showthread.php?t=818177
        Official documentation at this point is still being created, which is partly the reason for this post. More comprehensive and complete documentation will hopefully be forthcoming from the developers and volunteers. Of the existing documentation, I have have provided several links to the better sources at the end of this post.
        For troubleshooting and modifying the Grub menu, it is important to know which version you are using (Grub legacy, 0.97; Grub 2 in Karmic 1.97~beta4; Grub 2 in Lucid 1.9. To confirm the version of Grub used in your system, run this command:
        Code:
        grub-install -v
        Which should produce something like this:
        Quote:
        drs305@mycomputer:~$ grub-install -v
        grub-install (GNU GRUB 1.97~beta4)
      2. First Look Differences: GRUB vs GRUB 2
        At first boot, there will not be much difference in what the user sees on the boot menu. The one exception is a clean install of Ubuntu 9.10 with no other installed operating system. In this case, GRUB 2 will boot directly to the login prompt or Desktop without displaying a menu. Other major differences:
        • No ”/boot/grub/menu.lst”. It has been replaced by ”/boot/grub/grub.cfg”.
        • Hold down SHIFT to display the hidden menu during boot (formerly ESC is GRUB legacy).
        • There is no “find /boot/grub/stage1″ at the grub prompt. Stage 1.5 has also been eliminated.
        • The main menu file, ”/boot/grub/grub.cfg” is not meant to be edited, even by ‘root’.
        • ”grub.cfg” is overwritten anytime there is a update, a kernel is added/removed or the user runs `update-grub` *
        • The user can use a custom file, ”/etc/grub.d/40_custom”, in which the user can place his own entries. This file will not be overwritten.
        • The primary configuration file for changing menu display settings is ”/etc/default/grub”.
        • There are multiple files for configuring the the menu – ”/etc/default/grub” mentioned above, and all the scripts in /etc/grub.d/ folder.
        • Other operating systems, such as Windows, should automatically be recognized and added to the menu.
        • No changes made in the configuration files will take effect until the `update-grub` command is also run.
        * To update the GRUB 2 menu, the command sudo update-grub will be used throughout this guide. update-grub actually runs the command “grub-mkconfig -o /boot/grub/grub.cfg” This runs several scripts and incorporates the results into /boot/grub/grub.cfg which detemines what is seen on the screen during boot. Since the GRUB 2 developers do not intend to remove the update-grub ‘stub’, it will be used for simplicity and ease of use.
      3. Improvements
        GRUB 2′s major improvements over the original GRUB include:
        • New configuration file structure
        • Scripting support including conditional statements and functions
        • Dynamic module loading
        • Rescue mode
        • Themes – under development
        • Graphical boot menu support and improved splash capability
        • Boot Ubuntu LiveCD and some other ISO images directly from hard drive
        • Non-X86 platform support (such as PowerPC)
        • Universal support for UUIDs (not just Ubuntu)
        • Improved internationalization, including support for non-ASCII characters
      4. Booting Grub
        Grub 2 loads before the operating system. It’s modular components are loaded on an as-needed basis. Menu display behavior is generally determined by settings in /etc/default/grub. Review the “Grub 2 Files & Options” section for specific entry and formatting guidance. The main options for displaying the menu are:
        • Initial Default
          • Grub 2 will boot straight into the default operating system if no other operating system is detected. No menu will be displayed. If another operating system is detected, the Grub 2 menu will display.
        • Timed display.
          • The default delay is 10 seconds. If no user input is made Grub 2 boots to the default entry.
          • The countdown can be stopped by pressing any key. The user must then make a selection manually.
          • The booted entry is determined by the DEFAULT= setting in /etc/default/grub, The first “menuentry” is 0.
        • Hidden
          • The user can interrupt the boot process and display the menu by holding down the SHIFT key until the menu displays. Grub 2 searches for a depressed SHIFT key signal during boot. If the key is pressed or Grub 2 cannot determine the status of the key, the menu is displayed. Note: The “SHIFT” keystatus check is currently nested within in a conditional statement within /etc/grub.d/30_os-prober and may not work under certain circumstances.
          • The time the screen remains blank but available for display is determined by a setting in /etc/default/grub.
          • To provide visual feedback during while the countdown continues, a countdown display can be shown on the screen.
          • At the end of the timeout, the default entry determined in /etc/default/grub will be selected.
        • Saved
          • If the default option is set to “saved”, the last kernel/system successfully booted will be selected and run if no input is made.
          • Unlike GRUB, GRUB 2 stores the “saved” entry as a string, not as a menu position number. In GRUB 2, the result is applied more consistently. Example: If the first entry (kernel -15) becomes the second entry due to a kernel update, it will still be the “saved” entry even though it’s position on the menu has changed.
      5. Grub 2 Files & Options
        Many of the files in /boot/grub will not be recognizable by users of Grub Legacy. Especially noticeable are the multitude of *.mod files. Grub 2 is modular and these files are loaded as necessary by the grub bootloader. The Grub 2 user-configurable settings are contained mainly in /etc/default/grub and the files in /etc/grub.d. When update-grub is executed the results are input into the /boot/grub/grub.cfg file.
        • /boot/grub/grub.cfg
          • This is the main Grub 2 file. It “replaces” Grub Legacy’s /boot/grub/menu.lst This file contains the Grub menu information but unlike Grub Legacy’s menu.lst file, grub.cfg is not meant to be edited.
            • grub.cfg is automatcially generated when “update-grub” is executed:
            • Each section (### BEGIN) is clearly delineated and references the file in the /etc/grub.d folder from which the information was generated.
            • grub.cfg is updated by running the “update-grub” or “update-grub” command as root.
            • By default, and whenever the “update-grub” command is executed, this file is made “read-only”. This is in keeping with the intent that the file should not be edited manually. If you must edit this file, instructions are provided in Section 2.
       ----------------------------------
      1. How to Boot to the Recovery Mode wout. a Menu Option
        1. If you have Grub 2 set to boot without displaying the menu at all, hold the SHIFT key down until the menu displays. (In Grub it was the ESC key.)
        2. Press any key once the menu is displayed to ‘freeze’ it. Then arrow to the kernel you want to boot.
        3. Press “e”
        4. Scroll to the end of the “linux /boot/vmlinuz….” line. If displayed, remove “quiet” and/or “splash”. Add the word “single” to the end of the line.
        5. Press CTRL-X to boot to the Recovery menu.
      2. Uninstalling GRUB 2
        The command line produces a cleaner uninstall and reinstallation. While adding and removing the packages can be accomplished with Synaptic, certain steps must be accomplished in a terminal.
        • Open a terminal: Applications, Accessories, Terminal.
        • Make backup copies of the main GRUB 2 folders & files
          • Code:
            sudo cp /etc/default/grub /etc/default/grub.old
            sudo cp -R /etc/grub.d /etc/grub.d.old
            sudo cp -R /boot/grub /boot/grub.old
        • Remove GRUB 2
          • Ensure you have an Internet connection and reliable power source. An interruption of either could leave your system in an unbootable condition.
          • Code:
            sudo apt-get purge grub-common grub-pc
          • The user will be warned the system will be unbootable without installing another bootloader.
          • Once the packages are removed, many files will still remain in ‘/boot/grub’
        • Install GRUB 2
          • Code:
            sudo apt-get install grub-common grub-pc
            • The user will be asked for any special commands to add to the default “linux” line. If you aren’t sure, leave it blank, press the TAB key to highlight “OK” and press ENTER.
            • Select the appropriate drive on which to install Grub2 (sda, sdb, etc) by highlighting the entry and pressing the space bar. Normally a partition (sda1, etc) should not be selected.
          • Code:
            sudo update-grub
          • Reboot
      3. Reinstalling GRUB 2 from LiveCD
        If you cannot boot from GRUB 2 and need to reinstall it, here is the simple method. For more details or for advanced options, refer to the Ubuntu community documentation here: Grub2 – Reinstalling GRUB 2:
        • Boot the Karmic or Lucid LiveCD (Try without installing).
        • From the Desktop, open a terminal – Applications, Accessories, Terminal.
        • Determine your normal system partition – `sudo fdisk -l` (That is a lowercase L)
        • If you aren’t sure, run `df -Th`. Look for the correct disk size and ext3 or ext4 format.
        • Mount your normal system partition:
          Code:
          sudo mount /dev/sdXY /mnt
          • Example: sudo mount /dev/sda1 /mnt
          • Note: The partition to mount is normally the partition on which Ubuntu was installed: sda1, sdb5, etc. If you have a separate /boot partition, use the device on which the /boot partition is located. Grub 2 works best when installed in the MBR of the drive to which BIOS boots. Also remember that you mount the partition (including the number) in this step, but you do not include the partition number when you run the “sudo grub-install” command later.
          • Note: GRUB 2 counts the first drive (X) as “0″, but the first partition (Y) as “1″
        • Only if you have a separate boot partition:
          • Code:
            sudo mount /dev/sdXY /mnt/boot
            with sdXY being your /boot partition designation.
        • Reinstall GRUB 2:
          Code:
          sudo grub-install --root-directory=/mnt /dev/sdX
          • Example: sudo grub-install –root-directory=/mnt /dev/sda
          • Note: Substitute the device on which Ubuntu was installed – sda, sdb, etc. Do not specify a partition number.
        • Unmount the partition *:
          Code:
          sudo umount /mnt
          • * Note: If you mounted a separate /boot partition, unmount it first:
            Code:
            sudo umount /mnt/boot
        • Reboot.
      ..

      No comments: