GRUB2 is the latest version of GNU GRUB, the GRand Unified Bootloader. A bootloader is the first software program that runs when a computer starts. It is responsible for loading and transferring control to the operating system kernel. In Fedora, the kernel is Linux. The kernel then initializes the rest of the operating system.

GRUB2 is the follower of the previous version GRUB (version 0.9x). The original version is available under the name GRUB Legacy.

Since Fedora 16, GRUB2 has been the default bootloader on x86 BIOS systems. For upgrades of BIOS systems, the default is also to install GRUB2, but you can opt to skip bootloader configuration entirely.

Installing GRUB2 on a BIOS system

Normally, GRUB2 will be installed and set up by the installer, Anaconda, during the installation process. You will probably never have to deal with manual installation of GRUB2. However, in certain situations , you will want to install GRUB2 manually, especially if you need to repair the existing GRUB2 installation or you want to change its configuration.

This procedure shows the steps to install GRUB2 on your Master Boot Record (MBR) of your primary hard disk.

Before you start:

Before you start
  • Make sure you have the the GRUB2 packages and the os-prober package installed in your system:

    $ dnf list installed | grep grub
  • To automatically collect information about your disks and operating systems installed on them, the os-prober package needs to be installed on your system.

Procedure
  1. List block devices available on the system.

    $ lsblk
  2. Identify the primary hard disk. Usually, it is the sda device.

  3. Install GRUB2 in the MBR of the primary hard disk.

    $ sudo grub2-install /dev/sda
  4. Create a configuration file for GRUB2.

    $ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
  5. Reboot your computer to boot with the newly installed bootloader.

More information
  • The grub2-mkconfig command creates a new configuration based on the currently running system. It collects information from the /boot partition (or directory), from the /etc/default/grub file, and the customizable scripts in /etc/grub.d/.

  • The configuration format is changing with time, and a new configuration file can become slightly incompatible with the older versions of the bootloader. Always run grub2-install before you create the configuration file with grub2-mkconfig.

  • In Fedora, it is generally safe to edit /boot/grub2/grub.cfg manually. Grubby in Fedora patches the configuration when a kernel update is performed and will try to not make any other changes than what is necessary. Manual changes can be overwritten with grub2-mkconfig when the system gets upgraded with Anaconda. Customizations placed in /etc/grub.d/40_custom or /boot/grub2/custom.cfg files will survive running the grub2-mkconfig command.

Installing GRUB2 on a UEFI system

Normally, GRUB2 will be installed and set up by the installer, Anaconda, during the installation process. You will probably never have to deal with manual installation of GRUB2. However, in certain situations , you will want to install GRUB2 manually, especially if you need to repair the existing GRUB2 installation or you want to change its configuration.

This procedure shows the steps to install GRUB2 on a UEFI system on Fedora 18 or newer. The procedure consists of three parts.

Creating an EFI System Partition

The UEFI firmware requires to boot from an EFI System Partition on a disk with a GPT label. To create such a partition:

  1. List available block devices to find a place to create your ESP.

    $ lsblk
  2. Create at least a 128 MiB disk partition using a GPT label on the primary hard disk.

    $ sudo gdisk /dev/sda

    For the sake of this procedure, we assume that the created partition is recognized as /dev/sda1.

  3. Format the partition with the FAT32 file system.

    $ sudo mkfs.vfat /dev/sda1
  4. Create the /boot/efi directory as a mount point for the new partition.

    $ sudo mkdir /boot/efi
  5. Mount the partition to the /boot/efi mount point.

    $ sudo mount /dev/sda1 /boot/efi
  6. Proceed to the next part.

Install the bootloader files

In order to use GRUB2 with on the UEFI systems, you need to install or re-install appropriate packages:

  1. Re-install the necessary packages.

    dnf reinstall grub2-efi grub2-efi-modules shim
  2. If the above command ends with an error, install the packages.

    dnf install grub2-efi grub2-efi-modules shim
More information
  • This installs the signed shim and the GRUB2 binary.

Create a GRUB2 configuration

If you already have a working GRUB2 EFI configuration file, you do not need to do anything else.

Otherwise, create the configuration file using the grub2-mkconfig command.

$ sudo grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
More information
  • Under EFI, GRUB2 looks for its configuration in /boot/efi/EFI/fedora/grub.cfg.

  • For newly installed kernels to work, grubby expects /etc/grub2-efi.cfg to be a symlink to the real grub.cfg (for example /boot/efi/EFI/fedora/grub.cfg).

Creating the boot menu entries with UEFI bootloader

When you power on your system, your firmware will look for EFI variables that tell it how to boot. On running systems, which have booted into the EFI mode and their EFI runtime services are working correctly, you can configure your boot menu with efibootmgr.

If not, shim can help you bootstrap. The EFI program /boot/efi/EFI/BOOT/fallback.efi will look for files called BOOT.CSV in your ESP and will add boot entries corresponding to them. The shim command provides its own BOOT.CSV file that will add an entry for grub2-efi.

During the boot process, you can use the EFI Shell to invoke the fallback.efi profile to boot the system:

  1. Enter the boot partition.

    > fs0:
  2. Navigate into the EFI\BOOT directory.

    > cd EFI\BOOT
  3. Invoke the fallback.efi profile.

    > fallback.efi
More information
  • If you have no boot entries at all, then just booting off your disk in UEFI mode should automatically invoke /boot/efi/EFI/BOOT/BOOTX64.EFI, which will, in turn, invoke fallback.efi.

  • If you already have incorrect boot entries, you’ll either need to delete them or to modify BOOT.CSV to create new entries with different names.

Adding other operating systems to the GRUB2 menu

Normally, GRUB2 is preset to boot multiple operating systems during the Fedora installation process. If you can, it is advisable to install non-Linux operating systems first. Then, during the installation process, all those operating systems and their locations will be discovered and properly set.

Sometimes, however, you cannot use this approach and you will have to create the bootloader configuration file again to enable it to boot more operating systems.

Before you start
  • Make sure that the operating systems are on disks, connected to the system.

  • You have the os-prober package installed.

Procedure
  1. Install GRUB2 into the MBR of your primary hard disk.

    $ sudo grub2-install /dev/sda
  2. Recreate the GRUB2 configuration file.

    $ sudo grub2-mkconfig -o /boot/grub2/grub.cfg
More information
  • The grub2-mkconfig command will add entries for all operating systems it can find.

  • When problems appear, see the GRUB manual to solve issues with booting secondary operating systems.