Grub2

GRUB2 has been rewritten from scratch to clean up everything for modularity and portability.

For grub-1, a.k.a. "legacy" grub, see Quick GRUB page.

Installation
GRUB2 is in testing, so begin with adding the keyword. Note that GRUB2 is slotted, so we unmask the whole slot:

Now emerge GRUB2:

Configuration
For starters, the config files and syntax of GRUB2 is not compatible with GRUB1. GRUB2 does however come with a nice automatic configuration generating tool, grub-mkconfig. GRUB2's modules and config files are stored in to allow for both GRUB2 and Grub Legacy to be installed at the same time.

Syntax
GRUB2 has a slightly altered configuration syntax, including the numbering of partitions, which now start at 1, like linux partitions, but not drives, which still start at 0. So in a GRUB2 configuration file would be (hd1,3).

grub2-mkconfig
The following will automatically generate a GRUB2 configuration file including kernels images within your folder, using the auto configuration scripts in  and the variables in, the -o specifics an output file, here the default, :

it will produce an output similar to

Custom kernel arguments
Kernel boot options (e.g., , , , etc) are added by editing the file. Add wanted kernel parameters to the line, they should then be included next time you run.

Easy as lilo scripting
add this script to your system to make updating grub as easy as....

Appearance
Grub2 lets you set up backgrounds with few image file format restrictions by using modules like png, etc. and fonts. For fonts to work you need to emerge GRUB2 with the USE flag enabled.

Background
You can set the background by setting to point to the background image you want, i.e:

Theming
To set the theme you first need to set and then  to point to the  in the directory of your theme.

Custom Entries
The default files in are, ,  and. Note that the script requires that your kernels name start with kernel- or vmlinuz-. requires to be installed, if not it does nothing.

The files in are sequentially executed when grub-mkconfig is invoked. The first two digits in the filename gives the execution order. If you don't want a file to be executed, simply remove its execution right, for example to avoid the custom entries :

If you want to swap menu entries, simply change their name. For example, renaming the to  will put the custom entries before the linux ones.

You can add any custom file. The best way the customize the Grub looking is to add a script before any OS entry (e.g. 05_theme).

Microsoft Windows Entry
As an example, let's consider Windows XP being installed on the first partition of the second harddrive:

The remapping isn't needed if Windows is installed on the first hard drive's first partition(that's or in GRUB2 terms, (hd0,1). Also note that if Windows has its own MBR on a disk you should only set the root to the disk, e.g: 	set root=(hd1)

Memtest86+ Entry
Because memtest86+ behaves like a netbsd kernel, we have to load it this way, e.g.:

If this does not work and you obtain a message such as "error: invalid a.out header", try:

Chainloading to GRUB2
GRUB2 includes a boot image that's loadable from GRUB Legacy, so you can try it out without wiping out your existing, working MBR. To set up GRUB2 without actually writing to the MBR, run (or  if you installed grub2 with the  USE flag) like this:

This uses in place of the command that would write the MBR, which fools GRUB into thinking it succeeded in doing so, thus preventing GRUB from ever actually writing anything.

After this is done, you can create a GRUB boot entry that points to as though it was a normal Linux kernel:

If you are using GRUB2 instead of GRUB-LEGACY as the "base" GRUB, you have to use:

Verifying (qemu)
If you have qemu installed, you can test whether your boot loader will load or not using:

Writing to the MBR
As usual, you probably want Grub2 handling booting for all your operating systems on all your drives:

EFI
To boot GRUB2 with an UEFI you first need an UEFI enabled install. You have to specify that you want an EFI GRUB platform:

for x86_64 aka 64-bit UEFI firmware. (Re)emerge GRUB2 for the change to take effect.

You also need a UEFI SYSTEM PARTITION (>=200 MiB FAT32 - gdisk type EF00 or parted "boot" flag in GPT). This partition needs to be mounted at. This partition is different from partition.

Mount this partition:

Find out the path of grub2-install executable and edit the following variables inn the file

from

to

Then run

Check whether the grub2 modules and grub.efi are setup at. If they are not, follow the below steps -

The possible modules are listed in and should be given without the .mod suffix.

The grub.cfg also has to go in this directory:

Announcing GRUB2
This is somewhat problematic. You first need a UEFI booted Linux kernel. This kernel also needs the efivars kernel module:

If the kernel is EFI booted and the efivars module is installed, the command can be used and shows something like this:

BootCurrent: 000C Timeout: 0 seconds BootOrder: 000B,0005,0006,0007,0008,0009,000A Boot0000 Setup Boot0001 Boot Menu Boot0002 Diagnostic Splash Boot0003 Rescue and Recovery Boot0004 Startup Interrupt Menu Boot0005* USB CD: Boot0006* USB FDD Boot0007* ATA HDD2: Boot0008* ATA HDD0: Boot0009* USB HDD Boot000A* PCI LAN Boot000B* Windows Boot Manager

The program can be used to manipulate the EFI boot parameters, so GRUB2 can be anounced as bootloader. This is done(if GPT is used) by:

Enabling resume swap for suspend
Open up

with root privledges and add

Where XY is the swap partition location, which can be found by

It looks like you are using UUID instead and that's fine. /etc/default/grub only affects the current operating system so don't worry about every linux OS using grub to start using that swap. After finishing your edits, run

(substitute grub.cfg with whatever file grub reads at boot, e.g. it may be named /boot/grub/grub.efi) to update your grub startup information with what you changed in /etc/default/grub.

Before Chroot
uses to get information about your partitions and drives. If it cannot access, it will silently fail to create menuentries. Therefore, before chrooting run:

In Chroot
If you have a separate partition and plan to install grub2, be sure to mount only the root partition before chroot'ing, and not the boot partition as well. Mount later, once inside chroot. If you mount the partition before chrooting,  will not detect  as a separate partition and will assume  and root are on the same partition.

No automatic menuentries
assumes linux kernel files in have names starting with vmlinux or vmlinuz. so when you copy bzImage to make sure you rename it.

Recovery
If booting fails, boot using a LiveCD that ships with GRUB1, like the Gentoo LiveCD.

Mount the partition containing the root filesystem which contains the folder (for those with a separate  partition, you'll need to also mount that once the root file system is mounted).

From the LiveCD, install GRUB1 into the MBR with the --root-directory pointing to your Gentoo systems root:

Upon success, reboot.

If you still encounter errors installing, try using the GRUB1 command line tool. There are notes within the next section documenting it's simple usage and usually always works if the above fails.

Without "multislot"
This is here in case you didn't use multislot, hence, keeping the stable grub-0.97* series installed. And you also didn't make a bootable Grub rescue floppy. Please enable multislot USE Flag for an easy & safe fall back option!

This scenario details a manual uninstall of GRUB and then the installation of grub-0.97* using the Gentoo LiveCD.

If booting fails, boot using the Gentoo Install CD-Rom. (Or, if you still have another boot option such as an old floppy drive, create a bootable floppy using /bin/grub-mkrescue prior to rebooting.)

As noted above prior to upgrading, it is recommended you make a binary package of grub-0.97*, it will be located within /usr/portage/packages/All/grub-0.97*)

Boot with the Gentoo Install CD-Rom and setup a chroot. Then, unmerge grub and install a stable version.

Finally, install it while in the chroot:

If emerge fails to install grub-0.97, but the tarball is present, the you can try to either emerge it directly or just untaring it from the top folder.

Still fails?

If you used tar, you'll need to re-emerge grub-0.97 version as tar doesn't perform any Portage Package operations including entering the package into the system database.

If grub-setup fails, try manually installing the bootloader into MBR:

And then you're going to issue two commands into the Grub command line, we here assume the root in which resides is, if  is on its on partition it should point to that: grub> root (hd0,1) grub> setup (hd0) And, you should see the following: grub> root (hd0,1) Filesystem type is ext2fs, partition type 0x83 grub> setup (hd0) Checking if "/boot/grub/stage1" exists... yes Checking if "/boot/grub/stage2" exists... yes Checking if "/boot/grub/e2fs_stage1_5" exists... yes Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 16 sectors are embedded. succeeded Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,1)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded Done. grub> quit Reboot and you should be back to using the old Grub and ready for another round of Grub2 attempt!

Fixing /grub2/locale/en.mo.gz error
Some users may notice an error is printed a split second before the grub2 menu loads concerning /grub2/locale/en.mo.gz.

This is a known issue that's been reported upstream. See https://bugs.gentoo.org/show_bug.cgi?id=408599 for more details.

A workaround for this issue is to run grub2-mkconfig with LANG=C: LANG=C grub2-mkconfig -o /boot/grub2/grub.cfg

Grub wiki is lost
Grub wiki was at http://grub.enbug.org/ until Apr 2011 or so, but it's somehow lost. However, an archived copy of the wiki as of October 2010, can still be viewed at http://web.archive.org/web/20101005232749/http://grub.enbug.org/