Chapter 20. Working with the GRUB 2 Boot Loader
Fedora 21 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.
20.1. Configuring the GRUB 2 Boot Loader
GRUB 2 reads its configuration from the /boot/grub2/grub.cfg
file on traditional BIOS-based machines and from the /boot/efi/EFI/redhat/grub.cfg
file on UEFI machines. This file contains menu information, however, it is not supposed to be edited as it is generated by the /usr/sbin/grub2-mkconfig utility based on Linux kernels located in the /boot/
directory, template files located in /etc/grub.d/
, and custom settings in the /etc/default/grub
file. Any manual edits could therefore cause the changes to be lost during updates. The GRUB 2 configuration file, grub.cfg
, is automatically updated each time a new kernel is installed. Note that any changes to /etc/default/grub
require rebuilding the grub.cfg
file. To update the GRUB 2 configuration file manually, use the grub2-mkconfig -o
command as follows:
On BIOS-based machines, issue the following command as
root
:
~]# grub2-mkconfig -o /boot/grub2/grub.cfg
On UEFI-based machines, issue the following command as
root
:
~]# grub2-mkconfig -o /boot/efi/EFI/redhat/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 21 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' {
load_video
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
else
search --no-floppy --fs-uuid --set=root f19c92f4-9ead-4207-b46a-723b7a2c51c8
fi
linux16 /vmlinuz-3.17.4-301.fc21.x86_64 root=/dev/mapper/fedora-root ro rd.lvm.lv=fedora/swap rd.lvm.lv=fedora/root 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.8.0-0.40.el7.x86_64.img
line means that the initramfs
image is actually located at /boot/initramfs-3.8.0-0.40.el7.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 21.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
.