From Fedora Project Wiki

Introduction

GRUB 2 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, (Linux, in the case of Fedora). The kernel, in turn, initializes the rest of the operating system.

GRUB 2 has replaced what was formerly known as GRUB (i.e. version 0.9x), which has, in turn, become GRUB Legacy.

Starting with Fedora 16, GRUB 2 is the default bootloader on x86 BIOS systems. For upgrades of BIOS systems the default is also to install GRUB 2, but you can opt to skip bootloader configuration entirely.

Tasks / Common issues

Updating GRUB 2 configuration using grubby

The GRUB 2 packages contain commands for installing a bootloader and for creating a bootloader configuration file.

The grub2-install command installs the GRUB 2 bootloader usually in the master boot record (MBR), in free and unpartioned space. The bootloader files are placed in the /boot/ directory. You can install the GRUB 2 bootloader with:

# grub2-install /dev/sda

Grubby is a utility that updates the bootloader-specific configuration files. The utility is a recommended way for making routine changes to the kernel boot parameters and setting a default kernel.

Following are some of the selected illustrations of grubby usage:

  • To add one kernel parameter to a single boot entry:
# grubby --args=<NEW_PARAMETER> --update-kernel=/boot/vmlinuz-5.11.14-300.fc34.x86_64
  • To add multiple kernel paramters to a single boot entry:
# grubby --args="<NEW_PARAMETER1> <NEW_PARAMETER2 <NEW_PARAMETER_n>" --update-kernel=/boot/vmlinuz-5.11.14-300.fc34.x86_64
  • To add one kernel parameter to all currently existing and future boot entries:
# grubby --args=<NEW_PARAMETER> --update-kernel=ALL
  • To remove one kernel parameter from all currently existing and future boot entries:
# grubby --remove-args=<PARAMETER_TO_REMOVE> --update-kernel=ALL
  • To set the default kernel:
# grubby --set-default=/boot/vmlinuz-5.11.12-300.fc34.x86_64


Updating and repairing the GRUB 2 main configuration file

The /boot/grub2/grub.cfg is the main GRUB 2 configuration file. It is a static file that you rarely modify. Except in cases of disk replacement or installation of other Linux distributions

Discovering what firmware the machine is using

  • On UEFI system use:


<prc>


15:37, 4 May 2021 (UTC)15:37, 4 May 2021 (UTC)15:37, 4 May 2021 (UTC)15:37, 4 May 2021 (UTC)15:37, 4 May 2021 (UTC)15:37, 4 May 2021 (UTC)Quiet (talk) grub2-mkconfig will add entries for other operating systems it can find. That will be done based on the output of the os-prober tool.

That might however not work so well, especially not for booting other Linux operating systems, and especially not on UEFI systems. See http://www.gnu.org/software/grub/manual/grub.html#Multi_002dboot-manual-config .

Setting default entry

Warning.png
Please look to (default) kernel sysconfig options.
if file /etc/sysconfig/kernel have
UPDATEDEFAULT=yes
in every kernel update the grub entry is update to last entry, if you don't want that please set:
UPDATEDEFAULT=no
(write "no" in lower case)
Warning.png
Some parts of this section is wrong or outdated for F17 and later releases.
Be also aware of [Bug 768106 - grubby does not support grub2 set default="${saved_entry}" and replaces with "0"]. version grubby-8.28-1.fc19 has fixed issues with "Default Menuentry" as noted in the linked bug-report

Due to grub2-mkconfig (and os-prober) we cannot predict the order of the entries in /boot/grub2/grub.cfg, so we set the default by name/title instead.

Open /etc/default/grub and ensure this line exists:

GRUB_DEFAULT=saved

and ensure this line not exists:

GRUB_SAVEDEFAULT=true

or ensure this line exists:

GRUB_SAVEDEFAULT=false
Note.png
Note
If GRUB_SAVEDEFAULT is set to true, then, when an entry is selected, save it as a new default entry for use by future runs of GRUB. So, maybe, you need be sure that GRUB_SAVEDEFAULT is not set to true. GRUB_SAVEDEFAULT is only useful if GRUB_DEFAULT is saved.

Apply the change to grub.cfg by running:

grub2-mkconfig -o /boot/grub2/grub.cfg

Now list all possible menu entries

grep -P "submenu|^menuentry" /boot/grub2/grub.cfg | cut -d "'" -f2

Now set the desired default menu entry

grub2-set-default "<submenu title><menu entry title>"

Verify the default menu entry

grub2-editenv list
Note.png
Note
The above method fails to work on some F20 (and newer) systems due to a missing or improperly linked /boot/grub2/grubenv file. The /boot/grub2/grubenv is symbolic linked to /boot/efi/EFI/fedora/grubenv but /boot is not mounted at the time of booting. So grub2 does not have access to the environment variables. To fix this, change /boot/grub2/grubenv to point to ../efi/EFI/fedora/grubenv instead and your chosen default OS will boot without any problems.
Note.png
Note
There are other, simpler, ways of setting the default entry, but they are prone to error if/when grub2-mkconfig is re-run. These include directly setting the default in /boot/grub2/grub.cfg or setting GRUB_DEFAULT to either a number or an entry title in /etc/default/grub. Neither of these methods is recommended.

If you understand the risks involved and still want to directly modify /boot/grub2/grub.cfg, here's how you can do it:

Edit /boot/grub2/grub.cfg, and change the line

Stop (medium size).png
This is not the recommended method
This will not survive grub2-mkconfig. It might not even survive a kernel update.
set default="0" 

to

set default="5"


Enable Serial Console in Grub

To enable Serial console in grub add the following entry's to /etc/default/grub

( Adjust baudrate/parity/bits/flow control to fit your environment and cables)

GRUB_CMDLINE_LINUX='console=tty0 console=ttyS0,115200n8'
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1"

And re-generate grub

grub2-mkconfig -o /boot/grub2/grub.cfg

NOTE: in UEFI boot environment, use efi0 instead of --unit=0. If that doesn't work, check that your serial port is visible in your UEFI environment, e.g. by running devtree or dh -p SerialIO in EFI Shell. See this discussion for more information.

Further Reading