Redirected from page "GrubHowto"

Clear message

GRUB 2 is the default boot loader and manager for Ubuntu since version 9.10 (Karmic Koala). As the computer starts, GRUB 2 either presents a menu and awaits user input or automatically transfers control to an operating system kernel. GRUB 2 is a descendant of GRUB (GRand Unified Bootloader). It has been completely rewritten to provide the user significantly increased flexibility and performance. GRUB 2 is Free Software.

In this guide, GRUB 2 is version 1.98 or later. GRUB legacy (version 0.97) will be referred to as GRUB. To determine your version, use grub-install --version. Grub version 1.99 became the default on Ubuntu 11.04 (Natty Narwhal) and introduced some major changes in the Grub file contents. This guide covers the use of Grub 1.98, the Grub release found in Ubuntu 10.04 LTS (Lucid Lynx). and Grub 1.99, packaged with Ubuntu 12.04 LTS (Precise Pangolin). Content reflecting other versions of Grub 2 will be noted in the appropriate entry.

Improvements

GRUB 2's major improvements over the original GRUB include:

  • Scripting support including conditional statements and functions
  • Dynamic module loading
  • Rescue mode
  • Custom Menus
  • Themes
  • Graphical boot menu support and improved splash capability
  • Boot LiveCD ISO images directly from hard drive
  • New configuration file structure
  • Non-x86 platform support (such as PowerPC)
  • Universal support for UUIDs (not just Ubuntu)

GRUB vs GRUB 2

GRUB 2's default menu will look familiar to GRUB users but there are a great number of differences beneath the surface.

  • On a new installation of Ubuntu 9.10 or later with no other installed operating systems, GRUB 2 will boot directly to the login prompt or Desktop. No menu will be displayed.
  • Hold down (right) SHIFT to display the menu during boot. In certain cases, pressing the ESC key may also display the menu.
  • No /boot/grub/menu.lst. It has been replaced by /boot/grub/grub.cfg.

  • There is no "/find boot/grub/stage1" at the grub prompt. Stage 1.5 has been eliminated.
  • The main Grub 2 configuration file, normally located in the /boot/grub folder, is grub.cfg. It is the product of various scripts and should not normally be edited directly.

  • grub.cfg is overwritten by certain Grub 2 package updates, whenever a kernel is added or removed, or when the user runs update-grub.

  • The menu list of available Linux kernels is automatically generated by running update-grub.

  • The user can create a custom file in which the user can place his own menu entries. This file will not be overwritten. By default, a custom file named 40_custom is available for use in the /etc/grub.d folder.

  • The primary configuration file for changing menu display settings is called grub and by default is located in the /etc/default folder.

  • There are multiple files for configuring the menu - /etc/default/grub mentioned above, and all the files in the /etc/grub.d/ directory.

  • Partition numbering has changed. The first partition is now 1 rather than 0. The first device/drive is still hd0 by default (no change). These designations can be altered if necessary in the device.map file in the /boot/grub folder.

  • Automated searches for other operating systems, such as Windows, are accomplished whenever update-grub is executed. Operating systems found will be placed in the Grub 2 menu.

  • Changes made in the configuration files will not take effect until the update-grub command is executed.

Upgrading to GRUB 2 From GRUB

GRUB 2 is the default bootloader for Ubuntu. Users who still have Grub 0.97 installed on their Ubuntu systems can upgrade to GRUB 2 by installing the currently-supported releases of Ubuntu or by enabling repositories which contain the GRUB 2 package grub-pc.

Please visit the Grub2/Upgrading community documentation for more information and instructions.

File Structure

GRUB 2 incorporates a totally revised directory and file hierarchy. The major GRUB 2 folders include /etc/grub.d, which contains the main GRUB 2 scripts, and /boot/grub, which contains the GRUB 2 modules and menu file (grub.cfg). User customization's are normally made to the /etc/default/grub file.

The description of the major GRUB 2 folders and files is located on the Grub2/Setup community documentation page.

Configuring GRUB 2

Configuration changes are normally made to the /etc/default/grub file and to the custom scripts located in /etc/grub.d. No changes are made to the GRUB 2 menu until the update-grub command is run as root. This command runs the GRUB 2 configuration scripts and updates the /boot/grub/grub.cfg file.

Descriptions of the GRUB 2 options and how to change them are presented on the Grub2/Setup community documentation page.

Boot Display Behavior

GRUB 2 loads before any operating system. Its modular components are loaded on an as-needed basis. Menu display behavior is generally determined by settings in /etc/default/grub. Review the "Configuring GRUB 2" section above for specific entry and formatting guidance.

Initial Default

  • If no other operating system is detected GRUB 2 will boot straight into the default operating system and no menu will be displayed.
  • If another operating system is detected the GRUB 2 menu will display.

Timed Display

  • The menu is displayed for a predetermined number of seconds. The default entry is highlighted and other selections may be made by the user until the timeout expires. The default timeout is 2 seconds. The timer continues until any key is pressed or the highlighted entry is selected by pressing ENTER.

  • If no user input is made GRUB 2 boots the default entry at the end of the timeout period.
  • Once a key has been pressed the timeout is deactivated and the user must make a selection manually.
  • The default entry is determined by the GRUB_DEFAULT= setting in /etc/default/grub; the first "menuentry" has a value of "0".

Hidden

  • Normal Hidden Operations Enabled:
    • No menu entries are displayed. The splash screen, if configured, will be displayed.
    • The time the screen remains blank but available for display is determined by a setting in /etc/default/grub (GRUB_HIDDEN_TIMEOUT)

    • GRUB 2 can display a countdown timer to provide visual feedback on the time remaining until the default selection is chosen. The timeout setting is enabled in /etc/default/grub (GRUB_HIDDEN_TIMEOUT_QUIET)

    • The user may display the menu by pressing any key.
      • Once the menu displays, the GRUB_TIMEOUT counter begins. Pressing any key stops the countdown.
        • If no key is pressed by the end of the timeout the default entry determined by settings in /etc/default/grub will be selected.

  • Hidden Menu Operations Not Expected (Abnormal):
    • The user may be able to display the menu in one or more of the following ways:
      • Holding down the SHIFT key early in the boot process 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.
      • Pressing the ESC key during a 3 second window as GRUB 2 runs.

Saved

  • Saving an OS can be achieved by running sudo grub-set-default if GRUB_DEFAULT=saved is set in /etc/default/grub. It may also be saved if GRUB_SAVEDEFAULT=true is also set in /etc/default/grub. In this case, the default OS remains until a new OS is manually selected from the GRUB 2 menu or the grub-set-default command is executed.

Last Boot Failed or Boot into Recovery Mode

If the last boot failed or after a boot into Recovery Mode the menu will be displayed until the user makes a selection.

To change this behaviour, edit /etc/default/grub and add the variable GRUB_RECORDFAIL_TIMEOUT. Set the value similar to setting for GRUB_TIMEOUT.

  • For -1, there will be no countdown and thus the menu will display.
  • For 0, menu will not display even for a failed startup.
  • For >=1, menu will display for the specified number of seconds.

Run update-grub after the change have been made.

In some cases trick with GRUB_RECORDFAIL_TIMEOUT doesn't work. In such a case edit /etc/grub.d/00_header and change value of timeout in line 236 (this line is in the make_timeout() function)

set timeout=-1

to the the value as described above.

Run update-grub after the change have been made. Special thanks to McCunha on Ubuntu Forums for the above tip.

The above change, however, still causes GRUB2 to boot into text graphics mode. Thus, an additional change is required. Edit /etc/grub.d/10_linux and change line 188 to

set linux_gfx_mode=keep

Once again, run update-grub after the change has been made.

Password Protection

GRUB 2 is capable of password-protecting menu editing, access to the GRUB 2 terminal, and specific or all menu entries. It can also limit access to specific entries for specific users, and can encrypt plain-text passwords for increased security. Please refer to the Grub2/Passwords community documentation.

Custom Menu Entries

GRUB 2 allows users to create customized menu selections which will be automatically added to the main menu when sudo update-grub is executed. A 40_custom file is available in /etc/grub.d/ for use or to serve as an example to create other custom menus. Information on building and using custom menus in GRUB 2 is located in the Grub2/CustomMenus community document.

Troubleshooting

GRUB 2 provides excellent capabilities for troubleshooting and correcting boot problems from the boot menu or GRUB 2 terminal. Troubleshooting and recovery procedures are detailed in the Grub2/Troubleshooting community document which also includes a section Selected_Problems_and_Bugs.

Fixing reboot/shutdown freezes

If your machine freezes upon attempts to shutdown or reboot, try modifying /etc/default/grub. Open the file with gksudo gedit /etc/default/grub (graphical interface) or sudo nano /etc/default/grub (command-line). Any other plaintext editor (Vim, Emacs, Kate, Leafpad) is fine too. Find the line that starts with GRUB_CMDLINE_LINUX_DEFAULT and add reboot=bios to the end.

If done properly it should result in something like GRUB_CMDLINE_LINUX_DEFAULT="quiet splash reboot=bios"

Then save the file, run sudo update-grub and reboot in any way that's possible for you. After that, reboots and shutdowns should start working properly.

With certain hardware (notably DELL) the kernel parameter that you add needs to be reboot=pci (instead of reboot=bios), the procedure remains the same.

Displays

GRUB 2 can do more than provide a simple black & white menu. Its menu can be customized by the user to present a more visually-appealing menu by changing font colors, backgrounds and resolutions.

For information on using splash images and changing font colors and menu resolutions, please refer to the Grub2/Displays community documentation.

Themes

GRUB 2 Theming is still under development, as is integration with gfxmenu. Theme elements will include colors, fonts, progress indicators, menus, and labels. Both of these hold great promise but are not ready for release with Ubuntu 9.10. Check the Links section at the bottom of this page for references.

  • grub2.theme.dinxter.png

    grub2.theme.bennett.png

Installing/Reinstalling/Moving GRUB2

Please visit the Grub2/Installing community documentation. Information concerning upgrades from GRUB 0.97 (Legacy) to GRUB 2 is now located at Grub2/Upgrading.

Booting an ISO from a Menuentry

Ubuntu ISOs, as well as many utility ISOs and some other Linux operating systems, can be booted from a hard drive via a GRUB menuentry. This eliminates the need to create a CD/DVD and allows bootable image files to be stored only on the hard drive.

For information on this Grub 2 feature, please visit the Grub2/ISOBoot community documentation page.

Security

Preventing booting via Grub command-line

The ability to manually boot using the Grub command-line constitutes the biggest security risk in Linux. Any OS can be booted in this manner from any USB or CD/DVD drive, circumventing BIOS restrictions. Placing passwords or locking menu items (in the Grub configuration files) does not prevent a user from booting manually using commands entered at the grub command-line. (Once a foreign OS is booted, of course, it can be used to access any part of an unencrypted hard drive).

There are currently no options to prevent the command-line usage of Grub. Doing so would restrict boot-loading to just the menu options and that is not considered wise

Miscellaneous

Booting from a serial console

If you want GRUB to operate over a serial line, you will need to uncomment GRUB_TERMINAL in /etc/default/grub and set it to serial (instead of the console default). Alternatively, you can add GRUB_TERMINAL="console serial" to have the grub menu on both serial and local console. The default serial console settings are to operate on the first serial port (ttyS0) at a 9600 bit/s transfer rate with 8 data bits, 1 stop bit and no parity.

If you want to use another serial port or if your console uses different settings, you must add a GRUB_SERIAL_COMMAND line to specify additional parameters to the serial command. The serial command in GRUB 2 uses the same syntax as its GRUB Legacy counterpart (documented here). For example, for a very common 9600 bit/s (baud) serial line with 8 data bits, 1 stop bit and no parity:

GRUB_SERIAL_COMMAND="serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1"

An example is a 4800 bit/s (baud) serial line with 7 data bits, 1 stop bit and even parity:

GRUB_SERIAL_COMMAND="serial --unit=0 --speed=4800 --word=7 --parity=even --stop=1"

Booting FreeBSD, NetBSD, and chainload or multiboot OSes

Please refer to the article Grub2OtherOs community documentation page.

Links

External Links


CategoryBootAndPartition CategoryRescueAndCloning

Grub2 (last edited 2023-10-18 15:39:54 by aspen-logic)