GRUB2 Quick Start

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[edit | edit source]

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.

Standard PC (BIOS) support:

FILE /etc/portage/make.confPC BIOS GRUB_PLATFORMS example
GRUB_PLATFORMS="pc"

UEFI on amd64:

FILE /etc/portage/make.conf64-bit UEFI GRUB_PLATFORMS example
GRUB_PLATFORMS="efi-64"

Both standard PC (BIOS) and UEFI support:

FILE /etc/portage/make.confMultiple GRUB_PLATFORMS example
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[edit | edit source]

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.

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[edit | edit source]

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[edit | edit source]

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[edit | edit source]

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[edit | edit source]

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

Important
This is no longer necessary with sys-apps/systemd when the sysv-utils USE is enabled. This defaults to on with at least version 239 in Gentoo
FILE /etc/default/grubSystemd example
GRUB_CMDLINE_LINUX="init=/usr/lib/systemd/systemd"

Loading another operating system[edit | edit source]

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[edit | edit source]

Use of grub-mkconfig is not required. The grub.cfg file can be edited manually as well.

Migrating from the GRUB Legacy config format to the GRUB 2 config format is usually quite simple, requiring a few minor syntax changes.

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[edit | edit source]

  • GRUB2 - The 'full' GRUB2 article contains more information and an extensive list of resources.
This article is issued from Gentoo. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.