*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.
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.
The output returns only UEFI or BIOS, depending on the firmware your machine runs.
== 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
* 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
. List block devices available on the system.
+
----
$ lsblk
----
. Identify the primary hard disk. Usually, it is the `sda` device.
. Install *GRUB2* in the MBR of the primary hard disk.
+
----
# grub2-install /dev/sda
----
. Create a configuration file for *GRUB2*.
+
----
# grub2-mkconfig -o /boot/grub2/grub.cfg
----
. Reboot your computer to boot with the newly installed bootloader.
* 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 four parts.
[[create-an-esp]]
=== 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:
. List available block devices to find a place to create your ESP.
* Under EFI, *GRUB2* looks for its configuration in `/boot/efi/EFI/fedora/grub.cfg`, however the postinstall script of `grub2-common` installs a small shim which chains to the standard configuration at `/boot/grub2/grub.cfg` which is generated above. To reset this shim to defaults, delete the existing `/boot/efi/EFI/fedora/grub.cfg` and then reinstall `grub2-common`.
* For newly installed kernels to work, `grubby` expects `/etc/grub2-efi.cfg` to be a symlink to the real `grub.cfg` (for example `/boot/grub2/grub.cfg`).
[[solving-problems-with-uefi-bootloader]]
=== Solving problems 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:
. Enter the boot partition.
+
----
> fs0:
----
. Navigate into the `EFI\BOOT` directory.
+
----
> cd EFI\BOOT
----
. 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.
Adding other records into the *GRUB2* menu only means to run `grub2-mkconfig` command to regenerate the configuration files. During this process, all operating systems known to the system will be added into the configuration. By reinstalling *GRUB2*, this configuration will be used for further boots.
.Before you start
* Make sure that the operating systems are on disks, connected to the system.
* On BIOS systems, specify the disk where the bootloader should be installed.
+
----
# grub2-install /dev/sda
----
.More information
* The `grub2-mkconfig` command will add entries for all operating systems it can find.
* When problems appear, see the link:https://www.gnu.org/software/grub/manual/grub/grub.html#Multi_002dboot-manual-config[GRUB manual] to solve issues with booting secondary operating systems.
== Setting default entry for GRUB2
Since `grub2-mkconfig` (and *os-prober*) cannot estimate which operating system, of those it finds, is to be marked as default, we usually are unable to predict the order of the entries in `/boot/grub2/grub.cfg`. To change the default layout, we need to set the default based on the `name` or `title`.
.Before you start
. Open `/etc/default/grub` and make sure these lines exist in the file.
+
----
GRUB_DEFAULT=saved
GRUB_SAVEDEFAULT=false
----
. If you needed to change the content of the `/etc/default/grub`, apply the changes to `grub.cfg`.
. Regenerate the *GRUB2* configuration file and reinstall the bootloader into the MBR, as described in link:#adding-other-operating-systems-grub2[Adding other operating systems to the *GRUB2* menu].
.More information
If you understand the risks involved, you can manually modify the `/boot/grub2/grub.cfg` file. In that case, set the number of the default operating system using the `set default` variable.
For example:
----
set default="5"
----
[NOTE]
====
If you edit the configuration file manually, the settings will be overwritten each time the `grub2-mkconfig` command runs.
If improperly configured, *GRUB2* may fail to load and subsequently drop
to a boot prompt. To boot into the system, follow the steps below.
.Procedure
. Load the necessary modules to read your system's partitions (you will also need to load `part_msdos` or `part_gpt`, depending on your partition table).
+
* For BTRFS filesystems (Fedora 33 or newer).
+
----
grub> insmod btrfs
----
+
* For LVM filesystems (older than Fedora 33).
+
----
grub> insmod xfs
grub> insmod lvm
----
. List the drives which *GRUB2* sees.
+
----
grub> ls
----
. Examine the output to understand the partition table of the `/dev/sda` device. The following example shows a DOS partition table with three partitions.
+
----
(hd0) (hd0,msdos3) (hd0,msdos2) (hd0,msdos1)
----
+
A GPT partition table of the `/dev/sda` device with four partitions could look like this.
+
----
(hd0) (hd0,gpt4) (hd0,gpt3) (hd0,gpt2) (hd0,gpt1)
----
. Probe each partition of the drive and locate your `vmlinuz` and `initramfs` files.
+
----
grub> ls (hd0,1)/
----
+
The outcome of the previous command will list the files on `/dev/sda1`. The partition that contains the `/boot` directory is the correct one. There you will search for the full names of the `vmlinuz` and `initramfs` files.
. Follow the <<btrfs-boot-setup, Pre-boot setup for BTRFS>> or the <<lvm-boot-setup, Pre-boot setup for LVM>> to recover your system.
. After the pre-boot setup, boot the system.
+
----
grub> boot
----
. To restore the bootloader's functionality, regenerate the *GRUB2* configuration file and reinstall the bootloader, as described in xref:adding-other-operating-systems-grub2[Adding other operating systems to the *GRUB2* menu].
If you end up in *GRUB2* boot prompt, it is also possible to boot using a _configfile_ that's located on another
partition, as is often the case with multi-boot systems containing Ubuntu and Fedora. Follow the below procedure
if you need to boot from a configuration file on a different partition.
.Procedure
. Load the necessary modules to read your system's partitions (you will also need to load `part_msdos` or `part_gpt`, depending on your partition table).
+
* For BTRFS filesystems.
+
----
grub> insmod btrfs
----
+
* For LVM filesystems.
+
----
grub> insmod xfs
grub> insmod lvm
----
. Set *GRUB2* root to your `/boot` partition. On UEFI systems, you should set *GRUB2* root to the EFI system partition.
+
----
grub> set root=(hd0,msdos1)
----
. Set the path to the configuration file.
+
----
grub> configfile /grub2/grub.cfg
----
.More information
* The *hd0,msdos1* line shows the pertinent `/boot` partition, which holds the `grub.cfg` file. The setting may be different on your system. See also xref:_using_the_grub2_boot_prompt[Using the GRUB2 boot prompt] for more information.
If you wish to protect the *GRUB2* interactive edit mode with a password, but allow ordinary users to boot the computer, use the `grub2-set-password` command. You will be prompted for the password, and then will have to confirm it. The encrypted password will be stored in /boot/grub2/user.cfg.
To remove password protection, simply delete the user.cfg file.
. Regenerate the *GRUB2* configuration file, as described in xref:adding-other-operating-systems-grub2[Adding other operating systems to the *GRUB2* menu].
To remove password protection, simple remove the changes you made to the `/etc/grub.d/01_users` file and regenerate the *GRUB2* configuration file, as before.
Starting from Fedora 15, the `--password=<encrypted_grub_passwd> --iscrypted` kickstart option must be used if setting an encrypted *GRUB2* password in the kickstart file.
It has been reported by some users that *GRUB2* may fail to install on a partition's boot sector if the computer's floppy controller is activated in BIOS without an actual floppy disk drive being present. Such situations resulted in an _Absent Floppy Disk_ error.
To workaround this issue, go into the rescue mode and follow the procedure in link:#installing-grub-2-on-a-bios-system[Installing GRUB2 on a BIOS system] *GRUB2*, but use the `--no-floppy` option with the `grub2-install` command.
----
# grub2-install <target device> --no-floppy
----
== Using old graphics modes in bootloader
The terminal device is chosen with GRUB_TERMINAL. For more information, see the link:https://www.gnu.org/software/grub/manual/grub/grub.html#Simple-configuration[Grub manual].
Valid terminal output names depend on the platform, but may include `console` (PC BIOS and EFI consoles), `serial` (serial terminal), `gfxterm` (graphics-mode output), `ofconsole` (Open Firmware console), or `vga_text` (VGA text output, mainly useful with Coreboot).
The default is to use the platform's native terminal output.
In Fedora, `gfxterm` is the default options. To get the legacy graphics modes:
.Procedure
. Edit the `/etc/default/grub` file.
. Set the `GRUB_TERMINAL` variable to one of the above mentioned options.
. Regenerate the *GRUB2* configuration file and reinstall the bootloader into the MBR, as described in link:#adding-other-operating-systems-grub2[Adding other operating systems to the *GRUB2* menu].
. Regenerate the *GRUB2* configuration file and reinstall the bootloader into the MBR, as described in xref:adding-other-operating-systems-grub2[Adding other operating systems to the *GRUB2* menu].