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 -v. 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 Penquin). 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 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
Please visit the Grub2/Upgrading community documentation.
File Structure
GRUB 2 incorporates a totally revised directory and file hierarchy. The menu.lst of GRUB legacy is no longer used.
To find out where GRUB 2 is installed, the user can run the following commands:
Device: sudo grub-probe -t device /boot/grub
UUID: sudo grub-probe -t fs_uuid /boot/grub
The main directories and files used by GRUB 2 include:
/boot/grub/grub.cfg
grub.cfg is the file most closely resembling GRUB's /boot/grub/menu.lst. This file contains the GRUB 2 menu information but unlike GRUB's menu.lst the grub.cfg file is not meant to be edited.
Each section is clearly delineated with "(### BEGIN)" and references the script in the /etc/grub.d directory from which the information was generated.
grub.cfg is updated by running the update-grub command as root. The update-grub command is a stub for sudo grub-mkconfig -o /boot/grub/grub.cfg. For standardization, the command update-grub will be employed, run as "root" with sudo.
grub.cfg is automatically generated with kernel installations/removals, updates to some GRUB 2 packages, when update-grub is executed, or when other operations would affect the boot process.
- In early versions of GRUB 2, the file is "read-only". Later versions removed the "read-only" attribute although as a system file it is still owned by "root".
The user will also see a multitude of *.mod files in the /boot/grub directory. These files reflect the modular nature of GRUB 2 and are loaded during boot by GRUB 2 bootloader as required.
/etc/default/grub
This configuration file contains information formerly contained in the upper section of GRUB Legacy's menu.lst and items contained on the end of the kernel line. The entries in this file can be edited by a user with administrator (root) privileges and are incorporated into grub.cfg when it is updated. Specific configuration settings are detailed in the Configuring GRUB 2 section below.
/etc/grub.d/ (directory)
The scripts in this directory are read during execution of the update-grub command and their instructions are incorporated into /boot/grub/grub.cfg.
The placement of the menu items in the grub.cfg menu is determined by the order in which the files in this directory are run. Files with a leading numeral are executed first, beginning with the lowest number. 10_linux is run before 20_memtest, which would run before 40_custom. If files with alphabetic names exist, they are run after the numerically-named files.
Custom menu entries can be added to the 40_custom file or in a newly created file. Based on its name, 40_custom entries by default appear at the bottom of the menu. A custom file beginning with 06_ would appear at the top of the menu since its alphanumeric sorting would place it ahead of 10_ through 40_ files.
Only executable files generate output to grub.cfg during execution of update-grub. By default the files in the /etc/grub.d folder are executable.
- The major default files in this directory used by Ubuntu are:
00_header Sets initial appearance items such as the graphics mode, default selection, timeout, etc. These settings are normally imported from information from /etc/default/grub. Users normally do not need to make changes to this file.
05_debian_theme The settings in this file set the GRUB 2 background image, text colors, selection highlighting and themes. In the absence of a splash image, this file sets a monochromatic theme for the initial menu display. Information on how to set font renderings and splash images are discussed in the Splash Images and Themes section.
10_hurd Locates Hurd kernels. Not currently used.
10_linux Identifies kernels on the root device for the operating system in use and creates menu entries.
Note: All kernels residing in the boot folder are included in this section. If you don't want all your old kernels to appear in the menu, remove the kernels from the /boot folder.
Grub 1.99RC (Ubuntu 11.04) introduces the submenu concept. The latest installed kernel is displayed on the main menu. Additional kernels are located in a submenu.
20_memtest86+ Searches for /boot/memtest86+.bin and includes it as an option on the GRUB 2 boot menu. There is currently no line option to remove this entry from the menu. The display of memtest86+ can be inhibited by removing the executable bit from this file and running sudo update-grub.
30_os-prober This script uses os-prober to search for Linux and other operating systems and place the results in the GRUB 2 menu.
- The file is divided into 4 sections, representing the types of operating systems handled by the scripts: Windows, Linux, OSX, and Hurd.
Variables in this file determine the format of the displayed names in /boot/grub/grub.cfg and on the GRUB 2 menu. Users familiar with basic scripting can alter these variables to change the format of the displayed menu entries.
The user can insert an entry into /etc/default/grub which disables this script (see below).
By default os-prober ignores any disks that possess dmraid signatures, which can be listed via sudo dmraid -r -c (if installed).
- The file is divided into 4 sections, representing the types of operating systems handled by the scripts: Windows, Linux, OSX, and Hurd.
40_custom A template for adding custom menu entries which will be inserted into grub.cfg upon execution of the update-grub command. The contents of this file, below the "exec tail -n +3 $0" line and the default comments, are imported directly into /boot/grub/grub.cfg without any changes.
Configuring GRUB 2
Important note: Configuration changes are normally made to /etc/default/grub and to the custom files located in /etc/grub.d. Any changes made directly to the /boot/grub/grub.cfg are overwritten whenever update-grub is executed either by the user or when called automatically by various system functions.
After editing /etc/default/grub or the scripts in the /etc/grub.d folder the user should run sudo update-grub to incorporate the changes into the GRUB 2 menu.
Some of the most common changes, such as the default OS/kernel and menu timeout, can be changed from within a GUI applications such as StartUp-Manager or Grub Customizer. See the community doc StartUpManager for information about how to install and use this application.
/etc/default/grub (file)
- The main configuration file for changing default settings. The following lines are available for alteration by the user.
GRUB_DEFAULT - Sets the default menu entry. Entries may be numeric, a complete menuentry quotation, or "saved"
Ubuntu's version of Grub 1.99 introduced the submenu feature. Designating a default boot option located in the Previous Linux versions submenu requires special formatting. For information regarding the submenu feature, please refer to Grub2/Submenus
GRUB_DEFAULT=0 Sets the default menu entry by menu position. Counting of entries is the same as in GRUB - the first "menuentry" in grub.cfg is 0, the second is 1, etc.
Note: Grub 1.99 introduces a submenu menu structure. For a menu item in a submenu, the entry becomes a two-digit entry. The first entry is the position of the submenu title in the main menu. The second entry is the position within the submenu. If the submenu is the 3rd entry in the main entry, and the user wishes to boot the first entry in the submenu, it would be designated as "2>0"
GRUB_DEFAULT="xxxx" An exact menu entry, including the quotation symbols, may also be used. In this case, location in the menu will not matter. Example: GRUB_DEFAULT="Ubuntu, Linux 2.6.31-9-generic"
In a Grub 1.99 submenu, the format would first include the submenu number, followed by the title. Example: "2>Ubuntu, Linux 2.6.38-8-generic"
GRUB_DEFAULT=saved
- The information in this section applies to GRUB 1.98 and later.
- Enables the "grub-reboot" and "grub-set-default" commands to set the default OS.
The default OS will not be set by an interactive selection of an OS from the menu.
grub-set-default Sets the default boot entry until changed.
The format is sudo grub-set-default X, with X being the menu entry position (starting with 0 as the first entry) or the exact menu string.
Examples: sudo grub-set-default 3 or sudo grub-set-default "Ubuntu, Linux 2.6.32-15-generic"
To obtain the existing menu entry choice number (starting from 0) or the menu entry "string", run grep menuentry /boot/grub/grub.cfg
grub-reboot This command sets the default boot entry for the next boot only. The format of the command is the same as for grub-set-default (see above).
GRUB_SAVEDEFAULT= If set to true this setting will automatically set the last selected OS from the menu as the default OS on the next boot.
- No commands need be run to set the default OS.
- Any time a menu entry is manually selected from the GRUB 2 menu, it becomes the default OS.
This option currently does not work if your /boot directory resides on an LVM partition or RAID.
For this to work you must also set GRUB_DEFAULT=saved.
GRUB_HIDDEN_TIMEOUT=0
- Wait this many seconds for the user to press a key. During this period no menu is shown unless the user presses a key. If no key is pressed, control is passed to GRUB _TIMEOUT when the GRUB_HIDDEN_TIMEOUT expires.
- The developers envisioned using this setting with a GRUB_TIMEOUT value of 0. This would give users a period of time (GRUB_HIDDEN_TIMEOUT) to display the menu by pressing a key, after which the system would boot without the menu being displayed (GRUB_TIMEOUT=0). Note the GRUB_TIMEOUT value does not have to be 0.
- Single operating system:
GRUB_HIDDEN_TIMEOUT=0
- No menu is displayed. The system is immediately booted to the default OS.
- This is the default setting with only one identified operating system.
To display the menu under this condition, place a # symbol at the start of the line and ensure the GRUB_TIMEOUT setting is a positive integer.
If the value is set to 0, a keystatus check is performed to determine if the SHIFT key is depressed. If GRUB 2 determines the SHIFT key is depressed during the boot process, the menu will be displayed. This gives the user a method of interrupting an automatic boot which would normally not display the menu.
GRUB_HIDDEN_TIMEOUT=X
X is a positive integer (e.g. 1, 5, 10, etc)
The boot process will pause and display a blank screen or the designated splash image for X seconds. At the end of the time period, the system will boot. No menu will be displayed.
- While GRUB_HIDDEN_TIMEOUT is active, the menu can be displayed by pressing any key.
GRUB_HIDDEN_TIMEOUT=
No value entered after the = sign
- The menu will be displayed for the number of seconds designated by GRUB_TIMEOUT.
- Wait this many seconds for the user to press a key. During this period no menu is shown unless the user presses a key. If no key is pressed, control is passed to GRUB _TIMEOUT when the GRUB_HIDDEN_TIMEOUT expires.
GRUB_HIDDEN_TIMEOUT_QUIET=true
true No countdown is displayed. The screen will be blank.
false A counter will display on a blank screen for the duration of the GRUB_HIDDEN_TIMEOUT value.
GRUB_TIMEOUT=10
- This is the time period in seconds for the menu to be displayed.
- This instruction begins at the expiration of GRUB_HIDDEN_TIMEOUT.
- Setting this value to -1 will cause the menu to display until the user makes a selection.
- On a single OS system, by default this setting is not used and the menu will not display.
- To display the menu on each boot:
Place a comment symbol (#) in front of the GRUB_HIDDEN_TIMEOUT entry
- Make the GRUB_TIMEOUT value 1 or higher.
- To display the menu on each boot:
GRUB_DISTRIBUTOR=lsb_release -i -s 2> /dev/null || echo Debian
- Retrieves the descriptive name in the menu entry. (Ubuntu, Xubuntu, Debian, etc.)
GRUB_CMDLINE_LINUX
- Entries on this line are added to the end of the 'linux' command line (GRUB legacy's "kernel" line) for both normal and recovery modes. It is used to pass options to the kernel.
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
- This line imports any entries to the end of the 'linux' line (GRUB legacy's "kernel" line). The entries are appended to the end of the normal mode only.
- To view a black screen with boot processes displayed in text, remove "quiet splash". To see the grub splash image plus a condensed text output, use "splash".
- This line imports any entries to the end of the 'linux' line (GRUB legacy's "kernel" line). The entries are appended to the end of the normal mode only.
#GRUB_TERMINAL=console
- Uncomment to disable graphical terminal (grub-pc only)
#GRUB_DISABLE_LINUX_UUID="true"
- Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
The search line will still use UUIDs. The linux line will use the /dev/sdXY convention when this option is enabled.
#GRUB_GFXMODE=640x480
- You can remove the # symbol to make this line active. The entry sets the resolution of the graphical menu (the menu text size). It provides resolutions supported by the user's graphics card (e.g. 640x480, 800x600, 1280x1024, etc). The setting applies only to the boot menu display, not the resolution of the operating system that boots.
- Tip: Setting the same resolution in GRUB 2 and the operating system will decrease boot times slightly.
- Although not required, the user can also specify the color bit depth by appending it to the resolution setting. An example would be 1280x1024x24 or 640x480x32.
The user can also add multiple resolutions. If GRUB 2 cannot use the first entry, it will try the next setting. Settings are separated by a comma. Example: 1280x1024x16,800x600x24,640x480.
- If using a splash image, the resolution setting and the splash image size should be compatible for best results.
If using an entry that produces a "not found" message when running update-grub, try adding or changing the color bitdepth.
Resolutions available to GRUB 2 can be displayed by typing vbeinfo in the GRUB 2 command line. The command line is accessed by typing "c" when the main GRUB 2 menu screen is displayed.
If this line is commented (#) or the resolution is unavailable GRUB 2 uses the default setting determined by /etc/grub.d/00_header.
- In GRUB 1.99 (Natty) the 'optimum' resolution is selected by GRUB if no resolution is specified.
For a guide to changing resolutions when using a splash image see the Splash Images and Theming section.
- You can remove the # symbol to make this line active. The entry sets the resolution of the graphical menu (the menu text size). It provides resolutions supported by the user's graphics card (e.g. 640x480, 800x600, 1280x1024, etc). The setting applies only to the boot menu display, not the resolution of the operating system that boots.
GRUB_DISABLE_LINUX_RECOVERY=true
- Uncomment (remove the # symbol) to prevent the "Recovery" mode kernel options from appearing in the menu. If you want a "Recovery" option for only one kernel, make a special entry in /etc/grub/40_custom.
GRUB_INIT_TUNE="480 440 1"
- When uncommented, plays a single beep just prior to the Grub 2 menu display.
The format is tempo [pitch1 duration1] [pitch2 duration2] ...
tempo is set once and applies to all duration settings.
duration is the result of 60/tempo. A duration of 1 with a tempo of 60 would produce a 1 second beep. A duration of 1 with a tempo of 480 produces a .125 second beep.
- Caution: The menu is displayed after the tune is complete. Creating a long tune will delay the appearance of the menu.
Online documentation is available by typing info grub --index-search play in a terminal. It mentions the ability to play a tune with the command play file if the tune is composed with little-endian numbers.
- Additional options which may be included:
GRUB_BACKGROUND (Maverick or later) - Sets the background image, enter the full path to the image here. See splash image configuration above for further details and other options.
GRUB_DISABLE_OS_PROBER=true
- Enables/disables the os-prober check of other partitions for operating systems, including Windows, Linux, OSX and Hurd, during execution of the update-grub command.
For a list of available predesignated entries, run: grep DEVICE -A40 /usr/sbin/grub-mkconfig
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 for specific entry and formatting guidance.
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 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 10 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 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.
- Once the menu displays, the GRUB_TIMEOUT counter begins. Pressing any key stops the countdown.
- 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.
- Holding down the SHIFT key early in the boot process until the menu displays.
- The user may be able to display the menu in one or more of the following ways:
Saved
Saving an OS can be achieved by running sudo grub-set-default if 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. The timeout setting in /etc/default/grub do not apply in this case. To change this behaviour, /etc/grub.d/00_header must be modified (if statement checking recordfail at the end of 00_header).
Password Protection
GRUB 2 is capable of password-protecting menu editing, access to the GRUB 2 terminal, and specific or all menuentries. It can also limit access to specific entries to 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 detailed in the Grub2/Troubleshooting community document.
Included on the referenced page is a section on Selected_Problems_and_Bugs.
Displays
For information on using splash images and changing font colors and menu resolutions, please refer to the Grub2/Displays community documentation.
Signposting from older links
Some people may have old bookmarks leading to this page in which case these links might be useful to them but it's better to link to the sub-pages directly as the sub-sections here are only here temporarily while this main page gets broken-up into digestible sub-pages.
GRUB 2 Splash Images
Grub2/Displays#Installing_Splash_Images
Set the splash image
Grub2/Displays#Installing_Splash_Images
Set menu font and highlight colors
Grub2/Displays#Setting_Menu_Font_Colors
Testing Fonts and Splash Images
Grub2/Displays#Testing_Fonts_and_Splash_Images
Changing Resolutions w/ Splash Images
Grub2/Displays#Changing_Menu_Resolutions
Creating User Splash Images
Grub2/Displays#Creating_User_Splash_Images
Resolution Settings
Grub2/Displays#Resolution_Settings
Image Creation and Setup
Grub2/Displays#Image_Creation_and_Setup
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.
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.
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).
To prevent the command-line usage of Grub and require bootloading from menu options only, there are currently no options.
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). 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 multiboot OSes
Please refer to the article Grub2OtherOs
Links
Grub 2 (Ubuntu Wiki)