GRUB

From Gentoo Wiki
(Redirected from GRUB Legacy)
Jump to: navigation, search
Note
For GRUB version 2, see GRUB2.

GRUB (GRand Unified Bootloader), also known as GRUB Legacy or GRUB version 1, used to be Gentoo's default bootloader on x86 and amd64 CPUs. GRUB version 2 is a completely reworked and fundamentally different bootloader, and will not be covered in this article.

Installation

USE flags

USE flags for sys-boot/grub GNU GRUB boot loader

debug Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces global
device-mapper Enable support for device-mapper from sys-fs/lvm2 local
doc Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally global
efiemu Build and install the efiemu runtimes local
fonts Build and install fonts for the gfxterm module local
libzfs Enable support for sys-fs/zfs local
mount Build and install the grub-mount utility local
multislot Allow concurrent installation of sys-boot/grub SLOT 0 and sys-boot/grub SLOT 2 by renaming all programs. local
nls Add Native Language Support (using gettext - GNU locale utilities) global
sdl Add support for Simple Direct Layer (media library) global
static !!do not set this during bootstrap!! Causes binaries to be statically linked instead of dynamically global
test Workaround to pull in packages needed to run with FEATURES=test. Portage-2.1.2 handles this internally, so don't set it in make.conf/package.use anymore global
themes Build and install GRUB themes (starfield) local
truetype Build and install grub-mkfont conversion utility local

Emerge

root #emerge --ask sys-boot/grub:0

Specifying the 0 slot ensures that world updates will not install GRUB 2 (which resides in slot 2) unless specified.

Configuration

Considerations

Hard drive numbering starts from 0. Unlike GRUB2, in GRUB Legacy partition numbering also starts at 0.

Instead of installing GRUB in the MBR, it is possible to install to a partition.

GRUB gets boot information from the BIOS, and can chainload other boot loaders, even if Linux can't see them. An example is a BIOS supported software RAID. When a physical drive is set up as 2 logical drives, the second logical drive starts in the middle of the physical drives. Without dmraid, Linux does not see that second logical drive. But GRUB can chainload Windows on it.

If installing Windows and Linux on a computer with two drives, it may be desirable to install each OS on one of the disks. Before installing, change the boot order in the BIOS. After installation, make the Windows disk the second disk and use GRUB to chainload it. This way, by reinstalling Windows, the MBR of the first disk will not get affected and if GRUB can't boot, it is still possible to boot Windows by changing the boot order in the BIOS.

When chainloading Windows, GRUB needs to know the active Windows partition, which is not always the same as the partition which Windows labels as the startpartition.

USB disks

The key to understand GRUB is to remember, in what environment GRUB is running.

Suppose there are 3 internal SATA disks. A Gentoo is running on them and the goal is to install GRUB now on an external USB hard disk to boot a version of Gentoo, which is installed on the second partition of the USB disk.

The Linux system has the following device names:

  • /dev/sda, /dev/sdb and /dev/sdc: internal drives
  • /dev/sdd: USB disk

The configuration of GRUB, which is read while booting, is stored in /boot/grub/grub.conf. menu.lst in the same directory is a symlink to grub.conf.

The kernel and the Linux system of the USB drive is installed in /dev/sdd2. Following the example, now edit /mnt/sdd2/boot/grub/grub.conf, if the mounted USB partition is on /mnt/sdd2.

When GRUB boots from the USB disk, for GRUB itself it is the first hard disk. It should be written in grub.conf:

FILE grub.conf
default 0
timeout 10

title gentoo USB
root (hd0,1)
kernel /boot/kernel-3.4.9 rootwait root=/dev/sdd2

In contrast, the kernel sees the USB disk as /dev/sdd, the root= kernel parameter has to contain /dev/sdd2.

Tip
The rootwait parameter can be passed so that the kernel will wait until the USB disk is ready. The same applies for the installation of GRUB.

Here pass GRUB the names, under which Linux sees it now. First chroot into /mnt/sdd2. Fire up GRUB, passing the root of the USB Linux with

grub>root (hd3,1)

Then tell GRUB to install on the MBR of the USB disk with:

grub>setup (hd3)

Consequence: To boot the USB disk, regardless of how many disks are installed, there is a requirement of using an initramfs or something else.

If the root= parameter doesn't match the actual configuration, all is not lost. It is possible to edit the lines before booting. How this can be done, is explained in Knowledge Base:Adjusting GRUB settings for a single boot session

To get the USB disk boot without initramfs regardless of the number of installed disks, use a GPT partition table and the root=PARTUUID= kernel parameter as explained in this external link: Mounting root partition by UUID (no initrd needed)

Since kernel 3.8 and newer it is possible to use MBR 32-bit UUID, so it's possible to use a MBR partition table as well.

In this case PARTUUID refer to an MBR partition using the format SSSSSSSS-PP, where SSSSSSSS is a zero-filled hex representation of the 32-bit "NT disk signature", and PP is a zero-filled hex representation of the 1-based partition number.

To get "NT disk signature" one possibility is using fdisk:

root #fdisk -l /dev/sdd

The output will be something like Disk identifier: 0x2d6b036c, so assuming root partition is /dev/sdd2, the resulting line will be root=PARTUUID=2d6b036c-02
More info is available here: Description of PARTUUID feature

Using LABEL or UUID

Kernel boot parameters are real_root=LABEL= or real_root=UUID=.

Requires an initramfs.

Refer to Install Gentoo on a bootable USB stick for examples using lilo or syslinux.

See also