This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

GRUB2 Quick Start

From Gentoo Wiki (test)
Jump to:navigation Jump to:search

This article provides information on how to get up and running with GRUB2 in the simplest configurations. For more comprehensive information, see GRUB2. For a migration from GRUB Legacy to GRUB2, see GRUB2 Migration.

Installing GRUB2 software

The sys-boot/grub package is slotted which means both grub-0.97 and grub-2.xx may be installed at the same time. However, while both versions of GRUB can be installed simultaneously, only one version of GRUB may be active as the system's bootloader at a time.

To install GRUB2, first set the GRUB_PLATFORMS variable with one or more appropriate values in the system's make.conf. If unset, GRUB2 will guess which platform to use on the system. It guesses pc (which is the MBR style of installation) for x86/amd64 architectures.

FILE /etc/portage/make.confGRUB_PLATFORMS example
# Standard PC (BIOS)
GRUB_PLATFORMS="pc"
 
# UEFI on amd64
GRUB_PLATFORMS="efi-64"
 
# Both UEFI and PC
GRUB_PLATFORMS="efi-64 pc"

After the variable is set, emerge the software:

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

Activating the GRUB2 boot loader

Mount /boot if applicable:

root #mount /boot

When using an EFI platform, make sure that the EFI System Partition is available (mounted) at /boot/efi. This can either be through a specific mount point (at /boot/efi) or by having an entire /boot partition formatted with the FAT filesystem. This will effectually render /boot into a large EFI System Partition.

Presuming only /boot/efi is FAT:

root #mount /boot/efi

Run the grub-install utility to copy the relevant files to /boot/grub. On the PC platform, this also installs a boot image to the Master Boot Record (MBR) or a partition's boot sector.

To install GRUB2 to the MBR:

root #grub-install /dev/sda
Installation finished. No error reported.

To install GRUB2 on an EFI capable system:

root #grub-install --target=x86_64-efi
Installation finished. No error reported.
Important
When installing GRUB2 to an EFI capable system (like the example above) is giving troubles, make sure the GRUB_PLATFORMS variable is properly set in /etc/portage/make.conf

The grub-install command accepts a --target option to specify which CPU/Platform to install. If unspecified, grub-install will make a guess: on x86/amd64 it will use the i386-pc value by default.

Automatic configuration

GRUB2 is traditionally configured by using the grub-mkconfig program to generate a configuration file.

grub-mkconfig generates the configuration file based on template sections located in /etc/grub.d. The default templates should cover most common boot setups.

user $ls /etc/grub.d
00_header  10_linux  20_linux_xen  30_os-prober  40_custom  41_custom  README

The behavior of these templates can be controlled by setting variables in /etc/default/grub. See the GRUB manual for more information.

Kernel naming scheme

In order for grub-mkconfig to detect the available Linux kernel(s), their names must start with vmlinuz- or kernel-.

For example:

CODE Example kernel names that GRUB2 can detect
 /boot/vmlinuz-3.4.3
 /boot/kernel-2.6.39-gentoo
 /boot/kernel-genkernel-x86_64-3.17.1-gentoo-r1

When using an initramfs, its name should start with initramfs- or initrd- and end with .img. The version must match one of a kernel image. File names generated by genkernel will also work.

For example:

CODE Example initramfs names that GRUB2 can detect
 /boot/initrd.img-3.4.3
 /boot/initrd-3.4.3.img
 /boot/initrd-3.4.3.gz
 /boot/initrd-3.4.3
 /boot/initramfs-3.4.3.img
 /boot/initramfs-genkernel-3.4.3-gentoo
 /boot/initramfs-genkernel-x86_64-2.6.39-gentoo

To generate the grub.cfg file, execute the grub-mkconfig command like so:

root #grub-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.2.9
done

Silent kernel decompression

To silence kernel decompression at boot time, edit /etc/default/grub and add quiet to the GRUB_CMDLINE_LINUX_DEFAULT variable.

FILE /etc/default/grubSilent decompression example
GRUB_CMDLINE_LINUX_DEFAULT="quiet"

Systemd

To boot systemd while using GRUB2 make the GRUB_CMDLINE_LINUX variable look like this:

FILE /etc/default/grubSystemd example
GRUB_CMDLINE_LINUX="init=/usr/lib/systemd/systemd"

Loading another operating system

grub-mkconfig can also generate configurations to load other operating systems. This requires the sys-boot/os-prober package.

To boot Windows, the sys-fs/ntfs3g also needs to be installed. It allows for the grub-mkconfig utility to probe NTFS filesystems.

Manual configuration

Users do not need to use grub-mkconfig. The grub.cfg file can be edited manually as well.

As most users have experience with GRUB Legacy format, the next example shows how to write a GRUB2 configuration file based on information from the GRUB Legacy configuration.

grub.conf (GRUB Legacy) grub.cfg (GRUB 2)
timeout 5


title Gentoo Linux 3.2.12
root (hd0,0)
kernel /boot/kernel-3.2.12-gentoo root=/dev/sda3

timeout=5


menuentry 'Gentoo Linux 3.2.12' {
root=hd0,1
linux /boot/kernel-3.2.12-gentoo root=/dev/sda3
}

Note
GRUB Legacy numbers partitions starting with 0; GRUB2 numbers partitions starting with 1. Both bootloaders number drives starting with 0.

See also

  • GRUB2 - The 'full' GRUB2 article contains more information and an extensive list of resources.