Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Installation
GRUB 2 is installed by default on new installations of Ubuntu 10.04 . Releases such as Ubuntu 9.04 Jaunty Jackalope which are
upgraded to 9.10 will retain GRUB unless the user elects to upgrade to GRUB 2. Previous releases of Ubuntu can be upgraded to
GRUB 2 if the user desires.
You can check the current version installed on your system via Synaptic or from the command line. Open a Terminal and enter
the following:
grub-install -v
GRUB 2 should display a version number of 1.96 or later. Legacy GRUB is version 0.97.
Default Installation
GRUB 2 will be the default bootloader on LiveCD installations of Ubuntu 9.10, Karmic Koala.
The GRUB 2 package is grub-pc. The grub-common package will also be installed.
grub2 is a dummy transitional package. It can safely be removed and will not be shown as installed in Synaptic.
Upgrading to GRUB 2
Upgrading to GRUB 2 from GRUB (legacy) in Ubuntu 9.10 or earlier versions is relatively easy. Importantly, the upgrade offers
a process to ensure GRUB 2 will work on your machine before the user commits to a full conversion. Note however that the
developers made a decision to not use an automatic update to GRUB 2 as the default on upgrade installs. Users who upgrade to
Ubuntu 9.10 may continue to use GRUB if desired.
Before installing GRUB 2, refresh the repository indexes to ensure the system has the latest update list. This is normally
accomplished via sudo apt-get update in a terminal or refreshing the lists in a GUI package manager such as
Synaptic. Older GRUB packages may not contain updates which have fixed several bugs in the early versions of the
installer.
To upgrade to GRUB 2 install the grub-pc package. This package can be installed with Synaptic or running the command
below. Once the installation begins, a simple script will guide the user through the rest of the installation:
At this point the package manager may complain about version conflicts and offer a solution to un-install grub. And this may cause
you to worry that it might become impossible for you to use the "chain load to GRUB2 from legacy GRUB" option that is mentioned
below. But never fear - for some reason - taking the un-install GRUB option here does not prevent you booting with the legacy menu
described in step 4 below.
1. At the first prompt, read the message, tab to select "OK", then press ENTER.
2. After selecting "OK" the next option allows the user to test GRUB 2 by adding an entry to their normal
GRUB menu. Select "Yes" to place a Chainload option on the GRUB menu. When GRUB boots the next
time, the user can select a normal GRUB entry or transfer control to GRUB 2 via the Chainload entry.
3. The next step(s) will import sections from GRUB's menu.lst to the "Linux command line" (shown) and
possibly the "Linux default command line". These entries allow the user to enter any special commands such
as quiet, splash, noapic and others of that nature. GRUB 2 should automatically import these settings.
Normally the user should accept any existing entries and TAB to "OK". If necessary, entries can be added
later. Refer to the Configuring GRUB 2 section for more detail.
When installing on a fresh drive, you may need to mark the selected partition as bootable.
4. Once the system has installed GRUB 2, the user can reboot and will be greeted by an updated GRUB legacy menu. As
shown, the user will see a "Chainload" option which will test the GRUB 2 installation. Selecting the Chainload option
will transfer control to GRUB 2 and display a GRUB 2 menu.
4a. Jaunty users may experience an "Unrecognized device string" Error 11 when making a selection. If so, press "e" until
you see the line beginning with "grub edit> root". Change "root" to "uuid", ENTER, then boot by pressing "b". More
details on Error 11 are located in the Command Line and Rescue Mode section.
5. Test the new entries and note the Grub 1.9X version number (highlight added).
6. If the GRUB 2 menus function properly the user can upgrade to GRUB 2 at any time by running:
sudo upgrade-from-grub-legacy
During installation the user will be prompted to provide the device(s) on which to install GRUB 2. Use the UP/DOWN
keys to highlight a device (sda, sdb, etc), then the SPACE key to select the device. Once at least one device is selected, use
the TAB key to highlight OK and press ENTER. Failure to select a drive will result in a GRUB Error 15 and failure of the
installation.
Upon successful installation of GRUB 2, a message will inform the user that some GRUB Legacy configuration files are
still present and can be removed. The instructions provide the following command, which must be run as 'root': rm -
f /boot/grub/menu.lst* Use caution when running the rm command as "root". Incorrectly entering this
command could result in permanently deleting necessary system files.
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: sudo grub-probe -
t device /boot/grub for the device and sudo grub-probe -t fs_uuid /boot/grub for the UUID.
/boot/grub/grub.cfg
This 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 file 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.
The file is automatically updated with kernel installations/removals or other updates which would affect its output.
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.
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 as necessary by the GRUB 2 bootloader.
/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 files 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 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.
The default files in this directory 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 splash 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. How to set font
renderings and splash images are discussed in detail in the Splash Images and Themes section.
10_hurd Locates Hurd kernels. Not currently used.
10_linux Locates kernels on the root device for the operating system currently in use. It takes this information and
establishes the names displayed on the menu for these kernels. Thanks to the code in this file, it is not necessary (or
even possible) to explicitly construct the list of kernel names displayed on the menu. Note: If you don't want all your
old kernels to appear in the menu list, remove their files from /boot.
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 file uses os-prober, which searches for Linux and other operating systems. Results are placed in
grub.cfg based on the scripts in this file. 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. Alternatively, 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.
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. The
/boot/grub/grub.cfg file should not be edited by the user; changes to this file are made by configuration scripts. After editing
/etc/default/grub, you need to run sudo update-grub for your changes to take effect on the next boot.
Some of the most common changes, such as the default OS/kernel and menu timeout, can be changed from within a GUI
app called StartUp-Manager. 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. Upon installation, the following lines are available for alteration
by the user:
GRUB_BACKGROUND - Sets the background image, enter the full path to the image here. See splash image
configuration above for further details.
GRUB_DEFAULT - Sets the default menu entry. Entries may be numeric, a complete menuentry quotation, or "saved"
GRUB_DEFAULT=0 Sets the default menu entry by menu position. As in GRUB, the first "menuentry" in grub.cfg is
0, the second is 1, etc.
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"
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.
GRUB_HIDDEN_TIMEOUT=0
This setting determines how long a screen without the GRUB 2 menu will be displayed. While the screen is blank,
the user can press any key to display the menu.
The default behavior is to hide the menu if only one operating system is present. If a user with only Ubuntu wishes to
display the menu, place a # symbol at the start of this line to disable the hidden menu feature.
For at least GRUB 1.97~beta - the version found in Karmic - whether or not the menu can include a timeout delay
with a blank screen is dependent on whether GRUB 2 finds multiple operating systems.
Note to multiple-OS users: If GRUB 2's os-prober identifies additional operating systems while running the
/etc/grub.d/30_os-prober script the hidden menu timeout feature is disabled by conditional statements. This also
disables the ability to use the SHIFT key to display the menu during boot. Users with multiple operating systems
wishing to hide the menu can find script edits on various forums which will allow them to add a hidden timeout
feature to the boot sequence (for example: ubuntuforums).
GRUB_HIDDEN_TIMEOUT=0 on single operating system computers.
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.
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
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 now 3 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
No menu entries are displayed. The splash screen, if configured, will be displayed.
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.
The time the screen remains blank but available for display is determined by a setting in /etc/default/grub.
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
At the end of the timeout, the default entry determined by settings in /etc/default/grub will be selected.
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.
The name of the file determines the order of the selections in the menu. Numeric filenames are run first, followed by
alphabetic filenames.
10_linux entries will appear before 30_os-prober entries, which will be placed before 40_custom entries, which will
preceed my.custom.entries inputs.
A user wishing for the custom menu entries to appear first on the main menu could name the directory 06_xxx so its
listings are first in the menu.
The file must be made executable: sudo chmod +x /etc/grub.d/filename.
The contents of the file is added to grub.cfg without changes when the update-grub command is executed.
Unlike grub.cfg, custom files can be edited at any time, are not read-only, and can be owned by the user if desired.
Custom files are static. The contents will not be altered when new kernels are added or removed (unless the contents are
affected by user-added scripts).
If the custom file places the menuentry listings at the top of grub.cfg, the user may wish to confirm the /etc/default/grub
DEFAULT= setting after running update-grub. Make sure it still points to the desired menuentry listing. When counting, the
first "menuentry" in /boot/grub/grub.cfg is 0.
According to the default sample custom file (/etc/grub.d/40_custom) the first two lines of any custom file in /etc/grub.d
should be:
#!/bin/sh
exec tail -n +3 $0
The user can copy existing menuentries from the /boot/grub/grub.cfg file or from a GRUB legacy file. If the user wishes to
copy from a GRUB legacy menu.lst file:
A backup copy of this file may be in the /boot/grub directory if the user upgraded from GRUB to GRUB 2.
The following entries from the GRUB menu listing must be changed for them to work:
title is changed to menuentry. The line must end with {
root is changed to set root=
kernel must be changed to linux
Any partition designation (sda4, sdb6) must be changed, as GRUB and GRUB 2 count the partitions
differently. The first partition for GRUB 2 is 1, not 0. Devices still start the count at 0.
Look carefully at the format of any working GRUB 2 menulist entry to ensure the correct format is used.
General menuentry Construction Rules:
The first line must start with menuentry and end with {
The area between the quotation symbols is what will appear on the GRUB 2 menu. Edit as desired.
The last line of the menuentry must be }
Do not leave empty spaces at the end of lines
The set root= line should point to the GRUB 2 /boot location ( sdXY )
The root reference in in the linux line should point to the system partition.
If GRUB 2 cannot find the referenced kernel, try replacing the UUID with the device name (example:
/dev/sda6 ).
A sample entry copied from the grub.cfg and altered by the user might look like this:
menuentry "My Default Karmic" {
set root=(hd0,1)
search --no-floppy --fs-uuid --set cb201140-52f8-4449-9a95-749b27b58ce8
linux /boot/vmlinuz-2.6.31-11-generic root=UUID=cb201140-52f8-4449-9a95-749b27b58ce8 ro quiet splash
initrd /boot/initrd.img-2.6.31-11-generic
}
A sample entry for a hard drive version of SystemRescueCD installed per the instructions on the web site (on sda8).
menuentry "System Rescue CD" {
set root=(hd0,8)
linux /sysrcd/rescuecd subdir=sysrcd setkmap=us
initrd /sysrcd/initram.igz
}
Fallback mode
It is possible to configure Grub2 to fall back to a known good menu-entry if the default menu-entry for some reason fails to boot.
An example script that can be used for this is available at this webpage (in German).
TROUBLESHOOTING: If you are in this section, you are probably having problems booting to your OS. The following
sections detail methods to use the edit and command-line capabilities of GRUB 2 to attempt to boot the system. One of the
improvements of GRUB 2 is the ability to search the contents of partitions from the command line. If the instructions in the
following sections do not work, especially if accompanied by "not found" or "the kernel must be loaded first" messages, use the
following commands to explore the partitions. For Ubuntu, the /boot directory should normally contain at least one "vmlinuz"
kernel and an "initrd" .img file. The /boot/grub directory should normally contain "grub.cfg" and various ".mod" files. X is the
drive, starting with 0. Y is the partition number, starting with 1. For a pure Ubuntu install on a single drive, the main
drive/partition is often hd0,1. For dual-boot with Windows on a single drive, the normal location is often hd0,5. Use the ls
command by itself to see which drives/partitions are known to GRUB 2.
To explore the devices known to GRUB 2, press "c" from the GRUB 2 menu to enter the command line (if not already there):
Here are some useful tips and features for use with the GRUB 2 command line:
Turning off the splash image may make viewing the terminal easier. Press "c" to go to the command line and then type:
set color_normal=white/blue or the color combination you wish to use. "black" as the second entry retains the
menu's transparency and should be avoided as a selection if the user wants to work with a solid background color.
To prevent scrolling past the top of the screen, first run set pager=1, which acts like the terminal's "| more" command.
This will allow one full screen of data, with line advancement continued by pressing the ENTER key.
Type help to view a list of all the commands. Type help x to view help commands beginning with the letter "x". Tab
completion and using the up arrow to repeat commands work the same as in a normal terminal.
The TAB completion feature is very handy. At any point, pressing the TAB key may complete an entry, if the element is
unique, or display available options. Typing a few additional characters and pressing TAB again may allow tab completion
to finish the entry.
Command Result
background_image Load an existing background image. Use tab completion to help complete filename entries!
background_image=/usr/share/images/grub/ then tab to display a list of all images. Useful command
when initially testing splash images.
cat Use to display the current file contents. cat /boot/grub/grub.cfg , cat /etc/fstab
help View all available commands. Type help x to get a list of commands beginning with the letter x.
help xxx for information about the xxx command. This command should be preceded by running "set
pager=1", which acts like the terminal's "| more" command, to prevent scrolling past the top of the screen.
ls Used alone, lists all devices known to GRUB 2, such as (hd0) (hd0,1), etc. View available partitions with
ls. View /boot and /grub directory contents with `ls /boot, ls /boot/grub
initrd Load an initrd.
linux Load a linux kernel.
loopback Mount a file as a device. `loopback loop (hd0,2)/iso/my.iso
lsmod Display loaded modules
If the command line prompt is not already active press "c" to enter the Command Line mode. You will see the GRUB 2 prompt:
grub> or grub rescue>
If you wish to cancel and start over at any time, ESC will remove changes and return the user to the previous menu.
Use the following two commands to determine the device (drive) and partition of the system you wish to boot.
set When set is typed without additional entries the command displays the current GRUB 2 settings.
ls Run ls to see the devices recognized by GRUB 2. Example: (hd0) (hd0,1) (hd1,5) In this example sda, sda1,
sdb5 are recognized.
Expanded Instructions *:
Press ENTER after completing each line. Some entries will not provide feedback. This is normal.
If a "file not found" or similar error message is displayed while running these commands, ensure you are using the
correct X,Y values. The ls command can help determine the correct values. Once the X,Y values are confirmed run
the following command:
set prefix=(hdX,Y)/boot/grub
1*. set root=(hdX,Y) Type with correct X,Y results from the ls command and press ENTER.
Remember GRUB 2 counts the first drive as 0, the first partition as 1.
Example: If the Ubuntu system is on sda5, enter: set root=(hd0,5)
2*. linux /vmlinuz root=/dev/sdXY ro Example: linux /vmlinuz root=/dev/sda3 ro
* Wubi users see note.
3. initrd /initrd.img Selects the latest initrd image.
4. boot Boot to the latest kernel on the selected partition.
* Wubi users only - substitute these commands in Steps 1 and 2:
set root=(loop0)
linux /vmlinuz root=/dev/sdXY loop=/ubuntu/disks/root.disk ro
These changes are not permanent. After successfully booting into the system the user should run sudo update-
grub and inspect the GRUB 2 configuration file (/boot//grub/grub.cfg). For problems with booting the main linux
kernel, ensure the search, linux, and initrd lines in the [### BEGIN /etc/grub.d/10_linux ###] section of the file now
correctly point to the correct locations. The user may need to reinstall GRUB 2 (sudo grub-
install /dev/sdX).
If a GRUB 2 menu is not available for editing during the boot process the command line may still allow booting a specific kernel.
If GRUB 2 is looking in the correct location a user may be able to enter all the necessary information on the command line in a
single entry. This section will provide a step-by-step guide on how to enter this information. The line will look similar to the
following when completed:
Expanded Instructions *:
Press ENTER only after completing each step ("1", "2", "3" and "4").
set root=(hdX,Y)
Use the correct X,Y results from the ls command and ENTER. Remember GRUB 2 counts the first drive as 0,
the first partition as 1. For example, if the Ubuntu system is on sda5, enter: set root=(hd0,5)
* For a Wubi install inside Windows, substitute the following command:
set root=(loop0)
root=/dev/sdXY loop=/ubuntu/disks/root.disk
Afer typing linux /boot/, the user can TAB to display the available kernels. There is no space character after
"/". If no kernels are visible, the address in the "Set Root" section may be incorrect. Enter the correct kernel by
typing or using tab completion.
For the root=/dev/ section use the correct device such as "/dev/sda1", "/dev/sdb5", etc
Add any options, such as ro (read-only), at the end of the line (normally not required).
Once all the information on the line is correct it should look similar to the sample below.
linux /boot/vmlinuz-2.6.31-16-generic root=/dev/sda1 ro
When correctly typed and ENTER, if the linux kernel is found, a line similar to the "Linux-bzImage"
confirmation line highlighted below will appear.
If a "file not found" or similar error message occurs, either the device/partition/file does not exist or GRUB 2
is not looking at the correct drive, partition and/or directory. Determine the correct location using the ls
command and then run the following command. Repeat Step 2.
set prefix=(hdX,Y)/boot/grub
Afer typing initrd /boot/, the user can TAB to display the available initrd images. Do not leave a space after
the "/". If no images are visible, the address in the "Set Root" section may be incorrect. Enter the correct
image by typing or using tab completion.
Once all the information on the line is correct it should look similar to the sample below. Press ENTER. Look
for confirmation.
initrd /boot/initrd-2.6.31-16-generic
When correctly typed and entered, if the initrd image is found, a line similar to the "Initrd"" confirmation line
highlighted in the graphic above should appear.
Step 4. Boot
boot
Type the command and press ENTER.
Rescue Mode
The rescue mode is a major GRUB 2 enhancement. If GRUB 2 fails to find a useable grub.cfg and is unable to transfer control to
a kernel it will drop to a grub-rescue> prompt. From this prompt the user can investigate problems, make changes, and retry the
boot.
The prefix setting must correctly point to the grub folder before the majority of the rescue commands can work. Until the
prefix is correctly set and the linux module is loaded the kernel and initrd image cannot be loaded.
If the path to the grub folder (normally /boot/grub) is not correct, an unknown command or file not found message is likely.
To help locate or verify the correct system partition is selected, use the ls command. First use the ls command to find the known
partitions; then expand it's use to verify the location and contents of the grub folder. Examples:
ls returns drives and partitions located by Grub 2: (hd0) (hd0,1) (hd0,5) (hd1) (hd1,1)
ls (hd0,5)/boot returns the files and folders in sda5's /boot folder. If the path correctly points to Ubuntu's /boot folder the
result should include the kernel and initrd images and the grub folder. If the command does not find the correc
ls (hd0,5)/boot/grub returns the files and folders in the /boot/grub folder of sda5. If the path correctly points to Ubuntu's
/boot/grub folder the result should include numerous *.mod files.
With the Ubuntu grub folder located, the prefix and root settings must be properly set. In the example above, the Ubuntu grub
folder was located in sda5 (hd0,5). The command in this example would be:
set prefix=(hd0,5)/boot/grub
set root=(hd0,5)
The current prefix and root settings may be checked at any time with the set command. To remove a setting, use the unset
command (example: unset prefix).
Now the modules can be loaded. Modules must be loaded before they can be used. If a module has not been loaded a unknown
command error is displayed. If an incorrect path is specified, a file not found error message may be displayed.
The linux module must be loaded to be able to load both the kernel and the initrd image, others listed below such as the normal
module may also be loaded. To load the linux module with the proper prefix set, run this command.
insmod linux
or
insmod /boot/grub/linux.mod
The rescue mode provides fewer commands than the normal GRUB prompt line, but also provides these additional commands:
Command Result
dump Clears memory
exit Exit GRUB 2
normal Return to the standard "grub>" mode if possible.
Among the commands which can be used in the grub rescue mode if the normal module can be loaded:
boot cat chain help insmod linux
ls multiboot normal search set unset
For a successful boot from the rescue prompt, the prefix path and root= setting must be correct, the linux module
must be loaded, and the kernel (vmlinuz) and initrd image (initrd.img) must be accepted.
The user should attempt to load the normal module to regain more capabilities while in the Grub 2 terminal. Try
loading the normal GRUB 2 module with insmod normal, followed by normal on a separate line to activate the
module. If successfully loaded and activated, help and additional commands will be available.
Command Summary *:
1. ls
2. set prefix=(hdX,Y)/boot/grub
3*. set root=(hdX,Y)
4. set
5. ls /boot
6. insmod /boot/grub/linux.mod
7*. linux /vmlinuz root=/dev/sdXY ro
8. initrd /initrd.img
9. boot
* For Wubi installs (within Windows) only substitute these commands in Steps 3 and 7:
set root=(loop0)
linux /vmlinuz root=/dev/sdXY loop=/ubuntu/disks/root.disk ro
Expanded Instructions:
1. ls This will display the known devices and partitions. From this information, the user must determine the device
and partition on which the system is installed.
2. set prefix=(hdX,Y)/boot/grub If incorrect, "no such disk" or "not found" errors will occur later.
3. set root=(hdX,Y) In this command, X is the device/drive, starting with 0. Y is the partition, starting with 1.
Example: (hd0,1) is sda1. (hd2,5) is sdc5.
4. set Inspect the "prefix=" listing. It should match the root designation in Step 3, in the following format: prefix=
(hdX,Y)/boot/grub.
5. ls /boot/ Inspect the contents. The user should see varioius kernels, initrd images and the grub directory. If not,
use the ls command to inspect the device and attempt to find these files and directories. If necessary, set another
device as root.
6. insmod /boot/grub/linux.mod Load (insert module) the linux module. Without this module loaded, the user will
receive an "Unknown command linux" message when trying to load the kernel.
7. linux /vmlinuz root=/dev/sdXY ro Load the linux kernel, substituting the correct designations for "X" and "Y"
(example: sda1). The user will see a message showing the kernel has been loaded. (See graphic in the previous
section above)
* Wubi users must use the alternate command presented earlier.
8. initrd /initrd.img Load the initrd image. When pressing ENTER the user may or may not see a message in the
terminal. (See highlighted graphic above)
9. boot Attempt to boot using the information entered.
These changes are not permanent. After successfully booting into the system the user should run sudo update-
grub and inspect the GRUB 2 configuration file (/boot//grub/grub.cfg). For problems with booting the main linux
kernel, ensure the search, linux, and initrd lines in the [### BEGIN /etc/grub.d/10_linux ###] section of the file now
point to the correct locations. The user may need to reinstall GRUB 2 using sudo grub-
install /dev/sdX.
GRUB Errors
GRUB 2 does not report error numbers. If a number is associated with an error, it is a problem with the transition from GRUB
legacy to GRUB 2.
3. The user, who has a keen memory, remembers that "root" needs to be changed to "uuid". Using the arrow keys to position
the cursor, the "root" entry is replaced with "uuid". When finished editing, the user presses ENTER, then "b" to boot the
revised selection. Note these are different commands than used in GRUB 2.
If the user intends to keep the dual GRUB option, to correct the error open /boot/grub/menu.lst as root and change "root" to
"uuid" in second line of the "Chainload into Grub 2" menu entry.
To recover from this error, GRUB 2 must be reinstalled. Go to Reinstalling from the LiveCD for instructions.
If at the grub prompt, type ls and ENTER. If the command does not display all the partitions, reboot and enter your computer's
BIOS setup. Ensure the BIOS reports the full disk size. If it doesn't, check for LBA/partition settings or obtain a BIOS update
from the manufacturer.
If unable to eliminate the BIOS limitation, the user can create a separate /boot partition within the disk area seen by the BIOS.
CreateBootPartitionAfterInstall
The following guidance for setting the background image is for Grub 2 version 1.98 and later. This version is found on
Lucid Lynx, Ubuntu 10.04 and later releases. Earlier versions of Grub 2 (1.97), found in Karmic Koala 9.10, use a less intuitive
entry for setting the background. Refer to the Karmic Koala section for details.
The GRUB 2 splash images are controlled by the GRUB_BACKGROUND variable in '/etc/default/grub'. Open this file for
editing as root and find this line:
GRUB_BACKGROUND=/usr/share/images/desktop-base/moreblue-orbit-grub.png
Change the line to reflect the correct path and filename for the image you wish to use as the Grub background image.
Once you have entered the path and filename you can run sudo update-grub to add the information into grub.cfg. If
adding the splash image was successful, the user will see "Found background image..." in the terminal as the command is
executed. If this phrase is not seen, the image information was probably not incorporated into the grub.cfg file.
Find the following line and edit the highlighted area, replacing it with the path and name of the GRUB 2 splash image you
wish to use:
for i in {/boot/grub,/usr/share/images/desktop-base}/moreblue-orbit-grub.{png,tga} ; do
These lines are contained in /etc/grub.d/05_debian_theme. The lines to modify depend on whether or not a background image is
selected.
The first color is the text color; the second is the background color.
set color_normal=black/black
The code below sets the color of selected entries. The first color is the highlighted text color; the second is the
background color of the selected line. If /black is the second entry, the highlighted line will be transparent and
only the text will change color.
set color_highlight=magenta/black
/black is the GRUB 2 default transparency color when listed second. Change only the first color (i.e. xxxxx/black) if using
a splash image. If the second value in this line is changed to a color other than black the splash image will be hidden behind a
solid color background.
In the following graphic, the color_normal setting is white/black. The color_highlight setting is cyan/blue
These colors are available in GRUB 2. "black" as a second entry is considered "transparent".
Save the file if any changes are made and then update GRUB 2: sudo update-grub
Rather than rebooting to test the color combinations, the user can see the changes by using GRUB 2's command line during
the boot process.
Select the splash image and initial font colors as described above, update GRUB 2's files with sudo update-grub,
and reboot.
When the GRUB 2 splash image/menu appears, press any key to stop the countdown timer.
Press c to enter the GRUB 2 command line.
Experiment with various color/highlight modes. Make changes by typing:
set color_normal=first-color/black and/or set color_highlight=first-
color/second-color
Text colors are viewable immediately after the command is entered. You can use the "up" arrow to recall the last
command and edit it to quicky test different color combinations.
Once you are finished, press ESC to return to the menu.
Repeat as desired.
Remember the desired color combinations, boot normally and edit /etc/grub.d/05_debian_theme and make the
changes permanent.
If the user wishes to change the resolution of the GRUB 2 screen while using a splash image follow these steps:
Resolution Settings
GRUB 2 looks for a resolution setting in /etc/default/grub. If uncommented, the resolution is determined by this line:
GRUB_GFXMODE=640x480
If no setting is found in /etc/default/grub, GRUB 2 uses the resolution established in /etc/grub.d/00_header, which is set at
640x480.
In Ubuntu, refer to the System, Preferences, Display menu for available monitor resolutions, or run vbeinfo in the
GRUB 2 command line to display available resolutions.
1. Determine the resolution you will use for the GRUB 2 splash image.
2. Create or resize any image to to the appropriate size.
GRUB 2 currently supports .png, .tga, and 8-bit .jpg/.jpeg images.
If using GIMP, naming the file with the applicable extension will save the file in the given format.
3. Make the applicable changes in the GRUB 2 configuration files:
/etc/default/grub: Uncomment the GRUB_GFXMODE=640x480 line and change the value if the resolution will be
other than 640x480.
/etc/grub.d/05_debian_theme: Enter the correct path and filename in the following line. Refer to the previous section
for more information on how to edit this line.
for i in {/boot/grub,/usr/share/images/desktop-base}/moreblue-orbit-grub.{png,tga} ; do
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.
Reinstalling GRUB 2
There may be times when a user needs to either move or reinstall a GRUB 2 installation. GRUB 2 needs to be reinstalled when a
user is presented with a blank screen with only the word "GRUB", no prompt, and no ability to enter commands. This often
happens when the MBR of the booting device is altered and GRUB 2 is removed, such as when Windows is installed after
Ubuntu. Additionally, if a user cannot boot into an operating system at all, even using the rescue mode mode, a complete
reinstallation of GRUB 2 may be necessary.
This is a quick and simple method of restoring a broken system's GRUB 2 files. The terminal is used for entering commands and
the user must know the device name/partition of the installed system (sda1, sdb5, etc). The problem partition is located and
mounted from the LiveCD. The files are then copied from the LiveCD libraries to the proper locations and MBR. It requires the
least steps and fewer command line entries than the following methods. If for example Windows is on sda1 and Ubuntu is on
sda5, and Windows has overwritten the MBR, then the target for grub installation will be /dev/sda5, and the MBR in the boot
sector of sda will be re written for grub.
a. sudo fdisk -l
If the user isn't sure of the partition, look for one of the appropriate size or formatting.
Running sudo blkid may provide more information to help locate the proper partition, especially if the partitions
are labeled. The device/drive is designated by sdX, with X being the device designation. sda is the first device, sdb is
the second, etc. For most users the MBR will be installed to sda, the first drive on their system. The partition is
designated by the Y. The first partition is 1, the second is 2. Note the devices and partitions are counted differently.
4. Mount the partition containing the Ubuntu installation.
Example: sudo mount /dev/sda1 Note: If the user has a separate /boot partition, this must be mounted to /mnt/boot Note: If
the user has a separate /home partition, this must be mounted to /mnt/home. Encrypted home partitions should work.
5. Run the grub-install command as described below. This will reinstall the GRUB 2 files on the mounted partition to
the proper location and to the MBR of the designated device.
This is a quick and simple method of restoring a broken system's GRUB 2 files. The problem partition is located and mounted
from the LiveCD. The files are then copied from the broken system's /boot/grub directory to the proper locations and MBR. It
requires fewer steps and fewer command line entries than the following CHROOT method. For users with separate system
partitions, such as a separate /boot partition, or other special circumstances, using the CHROOT method may provide better
results.
If the partition isn't recognized, look for one of the appropriate size or label.
Once mounted, the user should see Ubuntu system directories such as /boot
3. Open a terminal by selecting Applications, Accessories, Terminal from the menu bar.
4. Run the grub-setup -d command as described below. This will reinstall the GRUB 2 files on the mounted partition to
the proper location and to the MBR of the designated device.
a. Determine the mount point by referring to the location box in Places. Replace XXXX in the command with the
UUID, or replace /media/XXXX with the correct location if the partition is not mounted in /media. The designation
may be a UUID, or a label, if the user has created one (see note).
b. If the location window is not in the format shown, click on the icon to the left to change the presentation.
c. When ready to copy the UUID/location, by highlighting it with the mouse. Paste it into the terminal by pressing the
middle mouse button. If using the keyboard, use CTRL-SHIFT-arrow to select and CTRL-C to copy the location and
CTRL-SHIFT-V to paste it into the terminal.
d. The device/drive is designated by sdX, with X being the device designation. sda is the first device, sdb is the second,
etc. For most users the MBR should be installed to sda, the first drive on their system.
Example:
sudo grub-setup -d /media/7848138a-41a0-4eba-8aed-d1b625ac8759/boot/grub /dev/sda
e. If the user gets a "error: Cannot open /boot/grub/device.map" message, add the -m switch and path to the
device.map to the command as follows:
Ubuntu 9.10 introduced a new application which can easily assign labels to existing partitions. Access Disk Utility
from the System, Administration menu.
METHOD 3 - CHROOT
This method of installation uses the chroot command to gain access to the broken system's files. Once the chroot command is
issued, the LiveCD treats the broken system's / as its own. Commands run in a chroot environment will affect the broken systems
filesystems and not those of the LiveCD.
1. Boot to the LiveCD Desktop (Ubuntu 9.10 or later). Please note that the Live CD must be the same as the system you
are fixing - either 32-bit or 64-bit (if not then the chroot will fail).
2. Open a terminal - Applications, Accessories, Terminal.
3. Determine your normal system partition - (the switch is a lowercase "L")
sudo fdisk -l
If you aren't sure, run
df -Th. Look for the correct disk size and ext3 or ext4 format.
4. Mount your normal system partition:
Substitute the correct partition: sda1, sdb5, etc.
sudo mount /dev/sdXX /mnt # Example: sudo mount /dev/sda1 /mnt
5. Only if you have a separate boot partition:
sdYY is the /boot partition designation (for example sdb3)
sudo mount /dev/sdYY /mnt/boot
6. Mount the critical virtual filesystems:
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
7. Chroot into your normal system device:
sudo chroot /mnt
8. If there is no /boot/grub/grub.cfg or it's not correct, create one using
update-grub
9. Reinstall GRUB 2:
Substitute the correct device - sda, sdb, etc. Do not specify a partition number.
grub-install /dev/sdX
10. Verify the install (use the correct device, for example sda. Do not specify a partition): sudo grub-install --
recheck /dev/sdX
11. Exit chroot: CTRL-D on keyboard
12. Unmount virtual filesystems:
sudo umount /mnt/dev/pts
sudo umount /mnt/dev
sudo umount /mnt/proc
sudo umount /mnt/sys
If you mounted a separate /boot partition:
sudo umount /mnt/boot
13. Unmount the LiveCD's /usr directory:
sudo umount /mnt/usr
14. Unmount last device:
sudo umount /mnt
15. Reboot.
sudo reboot
Post-Restoration Commands
Once the user can boot to a working system, try to determine why the system failed to boot. The following commands may prove
useful in locating and/or fixing the problem.
The grub-install command should be used rather than grub-setup under normal circumstances. grub-setup
will be called by grub-install when needed.
The command should specify a device and when executed will install the required GRUB files to the location called for in
the options. (example: sudo grub-install /dev/sda )
If the user attempts to run the command with a specific partition (example: sudo grub-install /dev/sda6 ) a
warning will be issued. Specifying a partition is not recommended due to the use of blocklists, which the developers
consider unreliable. An option is provided on how to override this recommendation if the user still wishes to do so.
The list of options available for grub-install can be displayed in a terminal with grub-install --help.
The man page for grub-install currently does not display the all the available options.
Uninstalling GRUB 2
Reverting to GRUB Legacy
If a user chooses to return to GRUB legacy (0.97), these steps will remove GRUB 2 and install GRUB.
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.
If the user receives an "Unrecognized device string Error 11" message on rebooting see the Resolving an "Unrecognized
Device String" (Error 11) section for instructions on how to edit the menu and make the system bootable.
Launchpad 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.
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. See the bug report for more details.
When your boot partition (the one providing /boot) is a LV, make sure not to have any LVM snapshots inside the containing VG.
At reboot this will render your system unbootable, dropping you in a "grub rescue>"-shell with the following message: "error:
no such disk."
The grub-rescue-shell provided does not help you, because all modules (esp. lvm) are unreachable. You'll have to boot from a
install medium and remove all snapshots that are in the same VG as your boot partition by hand.
This issue is extremely annoying if your server is in a remote datacenter since the origin of the problem cannot be spotted easily
and repairing the system may be hard.
While this will be fixed in the upcoming Maverick Meerkat 10.10 release, the current Lucid Lynx LTS 10.04 is affected.
A workaround would be to install ubuntu using a separated non-LVM partition for /boot if you are using LVM snapshots
regularly.
There's some kind of irony that if you're careful and take a LVM snapshot before upgrading (and possibly rebooting) your system,
this will trigger the bug.
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 4800 bit/s 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"
Links
GrubHowTo
Grub 2 (Ubuntu Wiki)
External Links
GNU GRUB
GNU GRUB2 Manual
Illustrated Dual Boot HomePage
Mac OS X (XNU) Support
Mac OS X Boot Snow Leopard
GRUB Manual - Themes
CategoryBootAndPartition CategoryRescueAndCloning
Page History