Grub2

Differences between revisions 52 and 129 (spanning 77 versions)
Revision 52 as of 2009-07-09 23:56:30
Size: 21640
Editor: adsl-152-188-221
Comment: Cleanup
Revision 129 as of 2010-10-26 04:54:02
Size: 52
Editor: c-67-169-130-5
Comment: page obsoleted by help.ubuntu.com entry; as far as I can tell, everything from here is in there; blanking page and redirecting
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
#title Grub 2

||<tablestyle="float:right; font-size: 0.9em; background:#F1F1ED;margin: 0 0 1em 1em;" style="padding:2.0em;"><<TableOfContents>>||

''GRand Unified Bootloader, version 2'' (Grub 2) is the second version of GNU GRUB. It is a data-processing program making it possible to charge an operating system. It can start by itself of the systems compatible with standard POSIX (GNU/Linux, *BSD, Mac OS, etc) and has the capacity to connect towards another charger of starting for the systems noncompatible with standard POSIX.

More than one continuity of the project GRUB Legacy precedent, GRUB 2 is a complete rewriting. Based on the research project PUPA, the purpose of GRUB 2 is to be a more modular charger of starting and portable that its predecessor. Some of the aims had by GRUB 2 are as follows:

    * a graphic interface;
    * the loading of modules at the object time rather than to compilation;
    * portability towards various material architectures (BIOS, EFI, Coreboot…) ;
    * a mode of help takes again the hand in the event of error of loading. stage1.5 were eliminated;
    * correction in the management of the classification of the partitions, thing which could not be brought back in GRUB.

== GRUB 2 Testing ==

Please follow this link and please help out with [[https://wiki.ubuntu.com/KernelTeam/Grub2Testing|GRUB 2 Testing.]]

== Installing / Upgrading ==

=== Installing (Ubuntu 9.10) ===

GRUB 2 will be installed by default on '''NEW''' installations of Karmic. If you have upgraded from '''Jaunty 9.04''' to '''Karmic 9.10''' you can follow the install instructions for Jaunty 9.04 below.

=== Installing (Ubuntu 9.04+) ===

 * open terminal
  `$ sudo apt-get install grub2`
 * select OK from grub-pc configuration
 * chainload from menu.lst, YES
 * linux command line, ENTER

note this is only temporary, you must make changes permanent

 * Open up a terminal
`$ sudo upgrade-from-grub-legacy`
GRUB 2 will then show you where it's booting from. On my test system it displayed '''(hd0) /dev/sda''' but this might differ on your system. If this is incorrect, you must edit '''/boot/grub/device.map''' to match your system and then run
`$ sudo grub-install'

GRUB 2 should be fully installed, with GRUB legacy removed, and it's configuration files backed up. GRUB legacy configuration files are located in '''/boot/grub''' and are named '''menu.lst*'''


== Grub 2 Files & Folders ==
While the main grub bootloader file continues to reside in the ''/boot/grub'' folder, it is no longer Grub's familiar ''menu.lst''. The main Grub 2 instruction file is now ''grub.cfg''. This file is produced by various scripts run when either the `"update-grub"` or `"update-grub2"` command is executed. The files primarily responsible for the content of ''grub.cfg'' are ''/etc/default/grub'' and individual script files located in ''/etc/boot.d/grub''

Many of the files in ''/boot/grub'' will not be familiar to users of Grub Legacy. Especially noticeable are the multitude of *.mod files in the /boot/grub folder. Grub 2 is modular and the *.mod files are loaded as necessary by grub. Despite the addition of these files, the total size of the /boot/grub contents is fairly close to that of Grub Legacy and should not require a larger /boot partition.


=== grub.cfg (/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 instructions. Unlike Grub Legacy's ''menu.lst'' file, '''''grub.cfg'' is ''not meant to be edited.'''''

 * ''grub.cfg'' is automatcially generated or updated whenever `"update-grub"` or `"update-grub2"` is executed. The command must be run as ''root''.
 * The scripts used to generate ''grub.cfg'' include the files contained in /etc/grub.d and information gathered from ''/etc/default/grub''
 * The file is divided into sections. Each section of the file is clearly delineated and is recognizable by the section header ''### BEGIN''. The information on this line references the file in the ''/etc/grub.d'' folder which is used to incorporate the information into ''grub.cfg''
 *By default, and whenever the `"update-grub2"` 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 later on this page.

 * Sample ''grub.cfg'' including two Ubuntu kernels, memtest86+, Windows and a custom entry (41_srcd) imported from an /etc/grub.d/ script:
~-
 {{{
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by /usr/sbin/update-grub using templates
# from /etc/grub.d and settings from /etc/default/grub
#

### BEGIN /etc/grub.d/00_header ###
set default=0
set timeout=5
set root=(hd0,5)
search --fs-uuid --set b02e1934-12dd-418a
if font /usr/share/grub/ascii.pff ; then
  set gfxmode=640x480
  insmod gfxterm
  insmod vbe
  terminal gfxterm
fi
### END /etc/grub.d/00_header ###

### BEGIN /etc/grub.d/05_debian_theme ###
set menu_color_normal=cyan/blue
set menu_color_highlight=white/blue
### END /etc/grub.d/05_debian_theme ###

### BEGIN /etc/grub.d/10_hurd ###
### END /etc/grub.d/10_hurd ###

### BEGIN /etc/grub.d/10_linux ###
set root=(hd0,5)
search --fs-uuid --set b02e1934-12dd-418a-be3a-9ff7d3e7e7ea
menuentry "Ubuntu, linux 2.6.28-13-generic" {
 linux /boot/vmlinuz-2.6.28-13-generic root=UUID=b02e1934-12dd-418a ro quiet splash vga800
 initrd /boot/initrd.img-2.6.28-13-generic
}
menuentry "Ubuntu, linux 2.6.28-13-generic (single-user mode)" {
 linux /boot/vmlinuz-2.6.28-13-generic root=UUID=b02e1934-12dd-418a ro single
 initrd /boot/initrd.img-2.6.28-13-generic
}
menuentry "Ubuntu, linux 2.6.28-11-generic" {
 linux /boot/vmlinuz-2.6.28-11-generic root=UUID=b02e1934-12dd-418a ro quiet splash vga800
 initrd /boot/initrd.img-2.6.28-11-generic
}
menuentry "Ubuntu, linux 2.6.28-11-generic (single-user mode)" {
 linux /boot/vmlinuz-2.6.28-11-generic root=UUID=b02e1934-12dd-418a ro single
 initrd /boot/initrd.img-2.6.28-11-generic
}
### END /etc/grub.d/10_linux ###

### BEGIN /etc/grub.d/20_memtest86+ ###
menuentry "Memory test (memtest86+)" {
 linux /boot/memtest86+.bin
}
menuentry "Memory test (memtest86+, serial console 115200)" {
 linux /boot/memtest86+.bin console=ttyS0,115200n8
}
### END /etc/grub.d/20_memtest86+ ###

### BEGIN /etc/grub.d/30_os-prober ###
menuentry "Microsoft Windows XP Home Edition (on /dev/sda1)" {
 set root=(hd0,1)
 chainloader +1
}
### END /etc/grub.d/30_os-prober ###

### BEGIN /etc/grub.d/40_custom ###
# This file is an example on how to add custom entries

### END /etc/grub.d/40_custom ###

### BEGIN /etc/grub.d/41_srcd ###
menuentry "SystemRescue CD on hard drive" {
        set root=(hd0,10)
        linux /sysrcd/rescuecd subdir=sysrcd setkmap=us
        initrd /sysrcd/initram.igz
}
### END /etc/grub.d/41_srcd ###
}}}
-~



=== grub (/etc/default/grub) ===
This file contains information previously found in the upper section of ''/boot/grub/menu.lst''. It contains settings primarily affecting Grub's menu display. This file can be edited by ''root'' to make changes to these settings; they will be imported into ''grub.cfg'' when `"update-grub2"` is executed.

~-
  {{{
# This file is sourced by update-grub, and its variables are propagated
# to its children in /etc/grub.d/
GRUB_DEFAULT=0
GRUB_TIMEOUT=4
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"

# Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

# Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux
#GRUB_DISABLE_LINUX_UUID=true


This 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 items in this file can be edited by a user with administrator (root) privileges. Grub developers have have placed explanatory comments within the file itself.
}}}
-~

 * ''GRUB_DEFAULT=0''
  * Sets the default menu entry. Grub 2 uses "menuentry" instead of Grub Legacy's "titles". Both begin counting with ''0''. The third "menuentry" item would be "DEFAULT=2".
 * ''GRUB_TIMEOUT=5''
  * No change from Grug Legacy. This is the number of seconds before the default entry is automatically booted.
 * ''GRUB_DISTRIBUTOR''=`lsb_release -i -s 2> /dev/null || echo Debian`
 * ''GRUB_CMDLINE_LINUX''
  * If it exists, this line imports any entries to the end of the ''linux'' command line (Grub Legacy's "kernel" line) for both normal and recovery modes. This is similar to the "altoptions" line in ''menu.lst''
 * ''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. This is similar to the "defoptions" line in ''menu.lst''
 * ''#GRUB_TERMINAL''=console
  * Uncomment to disable graphical terminal (grub-pc only).
 * ''#GRUB_DISABLE_LINUX_UUID''=true
  * Uncomment this line if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux.

=== /etc/grub.d/ (folder) ===
The files in this folder are read during execution of '`"update-grub2"`'command. The scripts in these files export the information they gather into ''/boot/grub/grub.cfg''

The order of the entries in the grub menu is based on the numerical order of the file names.
Custom entries can be added to the ''40_custom'' file or placed in a new file.

Any file created must be executable in order to be included in the ''grub.cfg'' file during the `"update-grub2"` command. This can be accomplished from the terminal with `"sudo chmod u+x /etc/grub.d/filename"`. The following is a very brief look at what the files accomplish.

 * ''00_header''
  * Loads settings from ''/etc/default/grub'', including visual presentations, timeout, and terminal options.

 * ''05_debian_theme''
  * Sets background, text colors, and themes.

 * ''10_hurd''

 * ''10_linux''
  * Locates kernels based on the distributor determined by the `"lsb_release -i -s"` results ("Ubuntu").
 * ''20_memtest86+''
  * If the file /boot/memtest86+.bin exists, it is included as a menu item.

 * ''30_os-prober''
  * Searches for other OS's and includes them in the menu.

 * ''40_custom''
  * A template for adding custom menu entries which will be inserted into ''grub.cfg'' upon execution of the `"update-grub2"` command. This and any other custom files must be made executable to allow importation into ''grub.cfg''. These files are placed in the Grub menu in the numerical order of the file name.

== Adding Entries to Grub 2 ==

''grub.cfg'' is updated when `''update-grub"` or `"update-grub2"` is run. Changes to ''grub.cfg'' should be made to the appropriate script files and not to the ''grub.cfg'' file itself. Note that the first comment in ''grub.cfg'' is ''"DO NOT EDIT THIS FILE"''. The file is ''read-only'' and is returned to this status anytime `''update-grub"` is run.

=== Automatic Entries ===

  * When `"update-grub"` is executed, Grub 2 will read ''/etc/default/grub'' and the files in contained in the ''/etc/grub.d'' folder. This combination will set the visual parameters of the grub menu (''/etc/default/grub'') and search for linux kernels, other operating systems, and items designated in user-created scripts in ''/etc/grub.d''.
  The script files in ''/etc/grub.d'' perform the following tasks:
   * ''10_linux'' searches for installed linux kernels.
   * ''30_os-prober'' searches for other operating systems.
   * ''40_custom'' and any other user-created files in the ''/etc/grub.d folder'' add menu items designated in the script files created by users.
  * The name of the file determines the order in the menu. 30_os-prober entries will be placed before 40_custom entries, which will be placed before any higher-numbered entries.
  * Any user-created file must be made executable. This can be done as ''root'' by running `"sudo chmod u+x /etc/grub.d/filename"`

=== User-defined Entries ===
Users with "root" privileges can create scripts in the ''/etc/grub.d/'' folder which will be incorporated into the ''grub.cfg'' file when `"update-grub"` is run.
 * The filename should take the format ''XX_name'', with ''XX'' being a number followed by an underscore and name.
 * The order the entry appears on the grub menu is based on numerical ordering of the files in ''/etc/grub.d''.
 * The file must be made executable ( `"sudo chmod u+x /etc/grub.d/filename"` ).
 * '''''Note the new partition naming convention.''''' Devices start counting from ''0'' as done previously. sd'''a''' is designated as "hd0", sd'''b''' is "hd1", etc. However the first ''partition'' is now designated as ''sda'''1'''''. Counting ''partitions'' does ''not'' start with "0". The '''fifth''' partition on ''sda'' is ''sda'''5''''').

 * A sample custom entry. This file creates menu items for running a SystemRescueCD installation on sdb10 and a custom kernel on sda1.
~-
  {{{
#!/bin/sh
echo "Adding SystemRescueCD & Custom Kernel" >&2
cat << EOF
menuentry "Boot SystemRescue CD from hard drive" {
        set root=(hd1,10)
        linux /sysrcd/rescuecd subdir=sysrcd setkmap=us
        initrd /sysrcd/initram.igz
}

menuentry "Ubuntu, linux 2.6.31-custom" {
 set root=(hd0,1)
 search --fs-uuid --set 40c00255-22b3-488b-ae7e
 linux /boot/vmlinuz-2.6.31-custom root=UUID=40c00255-22b3-488b-ae7e ro quiet splash
 initrd /boot/initrd.img-2.6.31-custom
}
EOF
}}}
-~

  * The line ''"echo "Adding SystemRescueCD" >&2"'' is not required. Including it in the file allows this line to be seen in the terminal when `"update-grub2"` is executed. It provides visual feedback that the entry has been found and entered. The entry, if in the correct format, will be inserted in ''grug.cfg'' whether or not this line is included in the file.

 * Manual Editing of ''grub.cfg''
  * If you ''must'' edit this file:
  {{{
sudo chmod +w /boot/grub/grub.cfg # Remove 'read-only', necessary even for "root"
sudo nano /boot/grub/grub.cfg # Edit as "root"
}}}
  * Note: This file is returned to 'read-only' status and user inputs are overwritten anytime the `"update-grub"` command is run.


=== Removing Entries from Grub 2 ===
Entries should be removed by editing or removing files in the ''/etc/grub.d folder''. The ''/boot/grub/grub.cfg'' file is read-only and should not normally be edited directly.

 * Automatically.
  * Kernels removed by Synaptic will automatically update ''grub.cfg'' and no user action is required.
  * Other operating systems which have been removed from the computer will also be removed from the menu once `"update-grub2"` is run as ''root''.

 * Manually.
  * To remove a user-created menu entry, remove the applicable file from the ''/etc/grub.d folder''.
  * If a custom script in the ''/etc/grub.d/'' folder contains multiple menu entries, individual items may be removed and others retained.
  * Once a file has been removed or edited, run `"update-grub"` to update ''grub.cfg''
  * Tip: If the user wants his custom entries to appear at the top of the menu, the file can be named a value less than ''"10_linux"'', such as ''"07_custom"''. Check the the ''"DEFAULT"'' value in ''/etc/default/grub'' points to the correct ''menuentry'' after making this change.

== Theming ==

'''As of version 1.96 of GRUB 2, theme support is not enabled'''

The GRUB graphical menu supports themes that can customize the layout and appearance of the GRUB boot menu. The theme is configured through a plain text file that specifies the layout of the various GUI components (including the boot menu, timeout progress bar, and text messages) as well as the appearance using colors, fonts, and images.

Take a look at this thread on [[http://ubuntuforums.org/showthread.php?t=1182436|Grub 2 Themeing]]

=== Splash Images ===

Great link [[http://members.iinet.net/~herman546/p20/GRUB2%20Splashimages.html|here.]]

=== Background Colors/Image ===

Background colors and images are configured in a script located in '''/etc/grub.d/''' if you look in there you will find a file called '''05_debian_theme''' which is the default color scheme for GRUB 2. Now to create your own color scheme you have a few options, you can copy and edit the default 05_debian_theme or create your own script.

All the files in /etc/grub.d/ are run in order, so if you have 2 theme files, 05_debian_theme and 06_mytheme, the latter (06_mytheme) will be run last, which will be the background you see.

==== Copy/Edit Default Colors ====
 * Copy the default color theme
{{{
$ sudo cp /etc/grub.d/05_debian_theme /etc/grub.d/05_debian_theme.BACKUP
$ sudo nano /etc/grub.d/05_debian_theme
}}}
 * Now you can edit the file to your hearts content.

==== Create a new theme file ====

 * Create the new theme file
{{{$ sudo nano /etc/grub.d/06_mytheme}}}
 * Now you can put whatever you want in here

== Commands ==

As GRUB 2 has been totally re-written, there are now some commands you might be used to in GRUB legacy that don't exist in GRUB 2. Take a look at the Grub 2 Command's List [[http://grub.enbug.org/CommandList|here.]]

== Recover Grub 2 via LiveCD ==

 * First, grab a copy of the latest [[http://www.ubuntu.com/getubuntu/download|Ubuntu LiveCD]] and boot it.
 * Open a terminal and type
{{{$ sudo fdisk -l}}}
 * Now, you need to remember which device listed is your linux distribution, for reference, /dev/sda1 will be used. Now we need to mount the filesystem to /mnt
{{{$ sudo mount /dev/sda1 /mnt}}}
 *If you have /boot on a separate partition, that need's to be mounted aswell. For reference, /dev/sda2 will be used.
{{{$ sudo mount /dev/sda2 /mnt/boot}}}
''Make sure you don't mix these up, pay attention to the output of FDISK''
  Now mount the rest of your devices
{{{$ sudo mount --bind /dev /mnt/dev}}}
 * Now chroot into your system
{{{$ sudo chroot /mnt}}}

You should be chroot'd into your system as root, you can now run commands as root, without the need for sudo.

 * Now you need to edit the '''/etc/default/grub''' file to fit your system
{{{$ nano /etc/default/grub}}}
 * When that is done you need to run '''update-grub''' to create the configuration file.
{{{$ update-grub}}}
 * To install GRUB 2 to the MBR, next you need to run '''grub-install /dev/sda'''
{{{$ grub-install /dev/sda}}}
 * If you encounter any errors, try '''grub-install --recheck /dev/sda'''
{{{$ grub-install --recheck /dev/sda}}}
 * Press Ctrl+D to exit out of the chroot.
 * Once you exit back to your regular console, undo all the mounting, first the /dev
{{{$ sudo umount /mnt/dev}}}
 * Now you can unmount the root system
{{{$ sudo umount /mnt}}}
 * And you should be free to restart your system right into GRUB 2 and then into your system installation.

== Errors ==

=== Dual-booting ===
Following this thread on the forums, users have seemed to come up with a Karmic work around for fixing your dual-boot problems...

{{{
$ sudo apt-get install --reinstall libdebian-installer4
$ sudo os-prober
$ sudo update-grub
}}}

=== --no-floppy ===

It seems after an update yesterday Monday June 22, 2009 that some users are experiencing a --no-floppy error. There is a simple workaround to this. Check out this [[http://ubuntuforums.org/showthread.php?t=1194714&page=2|thread]]

 * Edit your boot command with '''E'''
 * Remove all entries of '''--no-floppy'''
 * Boot into Ubuntu and backup your GRUB 2 configuration
{{{$ sudo cp /etc/grub/grub.cfg /etc/grub/grub.cfg.backup}}}
 * Then edit your configuration
{{{$ sudo nano /etc/grub/grub.cfg}}}
 * Delete all entries of '''--no-floppy'''

=== unkown command 'initrd' ===

This error came after upgrading from Jaunty 9.04 to Karmic 9.10 on June 23, 2009. The work around was to remove the search line from the boot line. Take a look [[http://imagebin.ca/view/eCL6fVac.html|here]] and notice the '''search --fs-uuid''' line and remove it.

 * Press `E` to edit your boot line
 * Remove the `search --fs-uuid` line completely
 * Press `Ctrl-C` to enter the GRUB command line
 * Type in `insmod linux` and press `ENTER`
 * Press `ESC` to go back
 * `CTRL-X` to boot

Once you get into your system you need to re-install grub to your device, mine was sda

 * `sudo grub-install /dev/sda`

This fixed the problem and now booting is back to normal.

=== sleep 'invalid number 0.1' ===

'''***Fix released June 24, 2009***'''

Floating sleeps was built in, but not configured in the newest version of busybox, here's the fix.
 
 * Add dupondje's [[https://launchpad.net/~dupondje/+archive/ppa|PPA]]
{{{
deb http://ppa.launchpad.net/dupondje/ppa/ubuntu karmic main
deb-src http://ppa.launchpad.net/dupondje/ppa/ubuntu karmic main
}}}
 * Update & Upgrade
{{{$ sudo apt-get update && sudo apt-get upgrade}}}
 * Update initramfs
{{{$ sudo update-initramfs -uk all}}}

=== Error 11 ===
==== After upgrading from GRUB Legacy ====
Error 11: Unrecognized device string...
 * press any key to continue
 * highlight "Chainload into GRUB 2"
 * press e
 * highlight "root xxxxxxxxxxxxxxxxxxxx"
 * press e
 * change "root xxxxxxxxxxxxxxxx" to "uuid xxxxxxxxxxxxxxxxxx"
 * press b to boot "uuid xxxxxxxxxxxxxxxxxxx"
 * load your kernel and press enter
----
CategoryBootAndPartition
#REFRESH 0 https://help.ubuntu.com/community/Grub2

Grub2 (last edited 2010-10-26 04:54:02 by c-67-169-130-5)