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
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) 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:
emerge --ask sys-boot/grub:2
Activating the GRUB2 boot loader
Mount /boot if applicable:
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:
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:
Installation finished. No error reported.
To install GRUB2 on an EFI capable system:
Installation finished. No error reported.
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.
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.
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-.
/boot/vmlinuz-3.4.3 /boot/kernel-2.6.39-gentoo /boot/kernel-genkernel-x86_64-3.17.1-gentoo-r1
/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:
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.
To boot systemd while using GRUB2 make the GRUB_CMDLINE_LINUX variable look like this:
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.
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)|
GRUB Legacy numbers partitions starting with 0; GRUB2 numbers partitions starting with 1. Both bootloaders number drives starting with 0.
- GRUB2 - The 'full' GRUB2 article contains more information and an extensive list of resources.