Product SiteDocumentation Site

Chapter 21. Working with the GRUB 2 Boot Loader

21.1. Introduction to GRUB 2
21.2. Configuring the GRUB 2 Boot Loader
21.3. Making Temporary Changes to a GRUB 2 Menu
21.4. Making Persistent Changes to a GRUB 2 Menu Using the grubby Tool
21.5. Customizing the GRUB 2 Configuration File
21.5.1. Changing the Default Boot Entry
21.5.2. Editing a Menu Entry
21.5.3. Adding a new Entry
21.5.4. Creating a Custom Menu
21.6. GRUB 2 Password Protection
21.6.1. Setting Up Users and Password Protection, Specifying Menu Entries
21.6.2. Password Encryption
21.7. Reinstalling GRUB 2
21.7.1. Reinstalling GRUB 2 on BIOS-Based Machines
21.7.2. Reinstalling GRUB 2 on UEFI-Based Machines
21.7.3. Resetting and Reinstalling GRUB 2
21.8. GRUB 2 over a Serial Console
21.8.1. Configuring the GRUB 2 Menu
21.8.2. Using screen to Connect to the Serial Console
21.9. Terminal Menu Editing During Boot
21.9.1. Booting to Rescue Mode
21.9.2. Booting to Emergency Mode
21.9.3. Changing and Resetting the Root Password
21.10. UEFI Secure Boot
21.10.1. UEFI Secure Boot Support in Fedora
21.11. Additional Resources
Fedora 25 is distributed with the GNU GRand Unified Boot loader (GRUB) version 2 boot loader, which allows the user to select an operating system or kernel to be loaded at system boot time. GRUB 2 also allows the user to pass arguments to the kernel.

21.1. Introduction to GRUB 2

GRUB 2 reads its configuration from the /boot/grub2/grub.cfg file on traditional BIOS-based machines and from the /boot/efi/EFI/fedora/grub.cfg file on UEFI machines. This file contains menu information.
The GRUB 2 configuration file, grub.cfg, is generated during installation, or by invoking the /usr/sbin/grub2-mkconfig utility, and is automatically updated by grubby each time a new kernel is installed. When regenerated manually using grub2-mkconfig, the file is generated according to the template files located in /etc/grub.d/, and custom settings in the /etc/default/grub file. Edits of grub.cfg will be lost any time grub2-mkconfig is used to regenerate the file, so care must be taken to reflect any manual changes in /etc/default/grub as well.
Normal operations on grub.cfg, such as the removal and addition of new kernels, should be done using the grubby tool and, for scripts, using new-kernel-pkg tool. If you use grubby to modify the default kernel the changes will be inherited when new kernels are installed. For more information on grubby, see Section 21.4, “Making Persistent Changes to a GRUB 2 Menu Using the grubby Tool”.
The /etc/default/grub file is used by the grub2-mkconfig tool, which is used by anaconda when creating grub.cfg during the installation process, and can be used in the event of a system failure, for example if the boot loader configurations need to be recreated. In general, it is not recommended to replace the grub.cfg file by manually running grub2-mkconfig except as a last resort. Note that any manual changes to /etc/default/grub require rebuilding the grub.cfg file.

Menu Entries in grub.cfg

Among various code snippets and directives, the grub.cfg configuration file contains one or more menuentry blocks, each representing a single GRUB 2 boot menu entry. These blocks always start with the menuentry keyword followed by a title, list of options, and an opening curly bracket, and end with a closing curly bracket. Anything between the opening and closing bracket should be indented. For example, the following is a sample menuentry block for Fedora 25 with Linux kernel 3.17.4-301.fc21.x86_64:
menuentry 'Fedora, with Linux 3.17.4-301.fc21.x86_64' --class fedora --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.17.4-301.fc21.x86_64-advanced-effee860-8d55-4e4a-995e-b4c88f9ac9f0' {
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint='hd0,msdos1'  f19c92f4-9ead-4207-b46a-723b7a2c51c8
          search --no-floppy --fs-uuid --set=root f19c92f4-9ead-4207-b46a-723b7a2c51c8
        linux16 /vmlinuz-3.17.4-301.fc21.x86_64 root=/dev/mapper/fedora-root ro rhgb quiet LANG=en_US.UTF-8
        initrd16 /initramfs-3.17.4-301.fc21.x86_64.img
Each menuentry block that represents an installed Linux kernel contains linux on 64-bit IBM POWER Series, linux16 on x86_64 BIOS-based systems, and linuxefi on UEFI-based systems. Then the initrd directives followed by the path to the kernel and the initramfs image respectively. If a separate /boot partition was created, the paths to the kernel and the initramfs image are relative to /boot. In the example above, the initrd /initramfs-3.17.4-301.fc21.x86_64.img line means that the initramfs image is actually located at /boot/initramfs-3.17.4-301.fc21.x86_64.img when the root file system is mounted, and likewise for the kernel path.
The kernel version number as given on the linux16 /vmlinuz-kernel_version line must match the version number of the initramfs image given on the initrd /initramfs-kernel_version.img line of each menuentry block. For more information on how to verify the initial RAM disk image, see Section 22.5, “Verifying the Initial RAM Disk Image”.


In menuentry blocks, the initrd directive must point to the location (relative to the /boot/ directory if it is on a separate partition) of the initramfs file corresponding to the same kernel version. This directive is called initrd because the previous tool which created initial RAM disk images, mkinitrd, created what were known as initrd files. The grub.cfg directive remains initrd to maintain compatibility with other tools. The file-naming convention of systems using the dracut utility to create the initial RAM disk image is initramfs-kernel_version.img.
For information on using Dracut, see Section 22.5, “Verifying the Initial RAM Disk Image”.