Line 48: | Line 48: | ||
The <code>grub2-mkconfig -o /etc/grub2.cfg</code> and <code>grub2-mkconfig -o /etc/grub2-efi.cfg</code> commands add entries for other detected operating systems. That will be done based on the output of the <code>os-prober</code> utility. | The <code>grub2-mkconfig -o /etc/grub2.cfg</code> and <code>grub2-mkconfig -o /etc/grub2-efi.cfg</code> commands add entries for other detected operating systems. That will be done based on the output of the <code>os-prober</code> utility. | ||
{{admon/note|To update the GRUB 2 configuration file on Fedora 33 and earlier use <code>grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg</code>. |}} | |||
== Repairing GRUB 2 == | == Repairing GRUB 2 == | ||
If your machine running Fedora 34 is not working because of the broken GRUB 2 bootloader, you | If your machine running Fedora 34 is not working because of the broken GRUB 2 bootloader, the first possible step to take is that you boot into the rescue mode to repair the already installed operating system. | ||
For more details see [https://docs.fedoraproject.org/en-US/fedora/rawhide/install-guide/advanced/Boot_Options/#sect-boot-options-rescue Booting Your Computer in Rescue Mode]. | For more details see [https://docs.fedoraproject.org/en-US/fedora/rawhide/install-guide/advanced/Boot_Options/#sect-boot-options-rescue Booting Your Computer in Rescue Mode]. | ||
Line 67: | Line 64: | ||
== Reinstalling GRUB 2 == | == Reinstalling GRUB 2 == | ||
The GRUB 2 packages contain commands for installing the bootloader and for creating the <code>grub.cfg</code> configuration file. | The GRUB 2 packages contain commands for installing the bootloader, and for creating the <code>grub.cfg</code> configuration file. | ||
The <code>grub2-install</code> command embeds two stages of the bootloader - one at LBA 0, and one in either the master boot record (MBR) gap, or the GUID Partition Table (GPT) BIOS Boot partition. The bootloader files are placed in the <code>/boot/</code> directory. | The <code>grub2-install</code> command embeds two stages of the bootloader - one at LBA 0, and one in either the master boot record (MBR) gap, or the GUID Partition Table (GPT) BIOS Boot partition. The bootloader files are placed in the <code>/boot/</code> directory. | ||
Line 73: | Line 70: | ||
To reinstall the GRUB 2 bootloader on systems running Fedora 34: | To reinstall the GRUB 2 bootloader on systems running Fedora 34: | ||
* Learn what firmware your | * Learn what firmware your machine is running. See [https://fedoraproject.org/wiki/GRUB_2#Discovering_what_firmware_the_system_is_running Discovering what firmware the system is running] section. | ||
* On UEFI systems run: | * On UEFI systems run: | ||
Line 94: | Line 91: | ||
</pre> | </pre> | ||
{{admon/warning| Do not use the <code>grub2-install</code> command on UEFI systems. On those systems, bootloaders are in the <code>shim</code> and <code>grub-efi</code> packages. By reinstalling those packages, the bootloaders are reinstalled to their proper location in <code>/boot/efi/</code> | {{admon/warning| Do not use the <code>grub2-install</code> command on UEFI systems. On those systems, bootloaders are in the <code>shim</code> and <code>grub-efi</code> packages. By reinstalling those packages, the bootloaders are reinstalled to their proper location in <code>/boot/efi/</code> on the EFI system partition. }} | ||
== Fixing a damaged GRUB 2 configuration file using a plaintext stub file == | == Fixing a damaged GRUB 2 configuration file using a plaintext stub file on UEFI-based systems== | ||
On Fedora 34 and later, you can repair a malfunctioning <code>grub.cfg</code> configuration file by creating a stub | On Fedora 34 and later, you can repair a malfunctioning <code>grub.cfg</code> configuration file by creating a stub. | ||
# Discover the Universally Unique Identifier (UUID) for the <code>/boot/</code> mount point: | # Discover the Universally Unique Identifier (UUID) for the <code>/boot/</code> mount point: | ||
Line 127: | Line 124: | ||
At the end of first line (<code>--set=dev</code>), there is the UUID value of the <code>/boot/</code> mount point. | At the end of first line (<code>--set=dev</code>), there is the UUID value of the <code>/boot/</code> mount point. | ||
The above example assumes default partitioning, where a separate ext4 file system is mounted | The above example assumes default partitioning, where a separate ext4 file system is mounted on the <code>/boot/</code> directory. In case of other configurations, you need to insert <code>/boot/</code> into line 2. For example: | ||
<pre> | <pre> | ||
Line 140: | Line 137: | ||
== Enabling serial console in GRUB 2 == | == Enabling serial console in GRUB 2 == | ||
On Fedora 34 and later, you can enable serial console for usage on virtual environments. The following procedure explains how to achieve this goal. | |||
<pre> | <pre> | ||
# grubby --args="systemd.journald.forward_to_console=1 console=ttyS0,38400 console=tty1" --update-kernel=/boot/vmlinuz-5.11.16-300.fc34.x86_64 | # grubby --args="systemd.journald.forward_to_console=1 console=ttyS0,38400 console=tty1" --update-kernel=/boot/vmlinuz-5.11.16-300.fc34.x86_64 | ||
</pre> | |||
The first command specifies the baud rate, console forwarding for <code>systemd</code>, what console to use (<code>tty1</code>) and on what kernel such changes should be applied. | |||
<pre> | |||
# grubby --set-default=/boot/vmlinuz-5.11.16-300.fc34.x86_64 | # grubby --set-default=/boot/vmlinuz-5.11.16-300.fc34.x86_64 | ||
</pre> | </pre> | ||
The second command ensures the specified kernel is going to be loaded by default on next reboot. | |||
For instructions on how to enable serial consol in GRUB 2 for baremetal machines, see [https://www.gnu.org/software/grub/manual/grub/html_node/Serial-terminal.html Using GRUB via a serial line]. | For instructions on how to enable serial consol in GRUB 2 for baremetal machines, see [https://www.gnu.org/software/grub/manual/grub/html_node/Serial-terminal.html Using GRUB via a serial line]. | ||
Revision as of 12:40, 1 June 2021
What is GRUB 2
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 GRUB version 0.9x, which has become GRUB Legacy.
GRUB 2 is the default bootloader on AMD64 and Intel 64 BIOS systems. For upgrades of BIOS systems the default is also to install GRUB 2, but you can opt to skip bootloader configuration entirely.
Changing kernel command-line parameters with grubby
The grubby
utility 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 parameters 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
file is the main GRUB 2 configuration file. It is a static file that you rarely need to modify. Except in cases of disk replacement or installation of another Linux distribution.
Discovering computer firmware
To discover what firmware your machine uses, run the following command:
- On UEFI systems:
# ls -ld /sys/firmware/efi
- On BIOS systems:
# ls -lrt /etc/grub2.cfg
A successful output of either of these commands indicate that you are running the corresponding firmware.
The grub2-mkconfig -o /etc/grub2.cfg
and grub2-mkconfig -o /etc/grub2-efi.cfg
commands add entries for other detected operating systems. That will be done based on the output of the os-prober
utility.
Repairing GRUB 2
If your machine running Fedora 34 is not working because of the broken GRUB 2 bootloader, the first possible step to take is that you boot into the rescue mode to repair the already installed operating system.
For more details see Booting Your Computer in Rescue Mode.
After completing steps specified in the previous link, run the following command to mount the root partition:
# chroot /mnt/sysimage
Reinstalling GRUB 2
The GRUB 2 packages contain commands for installing the bootloader, and for creating the grub.cfg
configuration file.
The grub2-install
command embeds two stages of the bootloader - one at LBA 0, and one in either the master boot record (MBR) gap, or the GUID Partition Table (GPT) BIOS Boot partition. The bootloader files are placed in the /boot/
directory.
To reinstall the GRUB 2 bootloader on systems running Fedora 34:
- Learn what firmware your machine is running. See Discovering what firmware the system is running section.
- On UEFI systems run:
# dnf reinstall shim-* grub2-efi-*
- On BIOS systems:
- Find the device node the
/boot/
directory is located on:
- Find the device node the
# mount | grep "/boot " /dev/sda4 on /boot type ext4 (rw,relatime,seclabel)
The device node is /dev/sda4
.
- Reinstall the bootloader while specifying the device node without the number:
# grub2-install /dev/sda Installing for i386-pc platform. Installation finished. No error reported.
Fixing a damaged GRUB 2 configuration file using a plaintext stub file on UEFI-based systems
On Fedora 34 and later, you can repair a malfunctioning grub.cfg
configuration file by creating a stub.
- Discover the Universally Unique Identifier (UUID) for the
/boot/
mount point:
# lsblk --fs NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINT sr0 iso9660 Joliet Extension Fedora-WS-Live-34-1-2 2021-04-23-11-17-40-00 0 100% /run/media/jdoe/Fedora-WS-Live-34-1-2 zram0 [SWAP] vda ├─vda1 ext4 1.0 dc29837b-22dc-4469-be85-fc9acf3009fd 699.8M 21% /boot └─vda2 btrfs fedora_localhost-live c58f3698-5587-40f2-b920-64d46c43161d 23.7G 14% /home
The UUID of /boot/
is dc29837b-22dc-4469-be85-fc9acf3009fd
.
- Create a custom grub.cfg file with the following content:
search --no-floppy --fs-uuid --set=dev dc29837b-22dc-4469-be85-fc9acf3009fd set prefix=($dev)/grub2 export $prefix configfile $prefix/grub.cfg
At the end of first line (--set=dev
), there is the UUID value of the /boot/
mount point.
The above example assumes default partitioning, where a separate ext4 file system is mounted on the /boot/
directory. In case of other configurations, you need to insert /boot/
into line 2. For example:
... set prefix=($dev)/boot/grub2 ...
- Move or copy the custom grub.cfg file you created in the previous step to /boot/efi/EFI/fedora/grub.cfg
Enabling serial console in GRUB 2
On Fedora 34 and later, you can enable serial console for usage on virtual environments. The following procedure explains how to achieve this goal.
# grubby --args="systemd.journald.forward_to_console=1 console=ttyS0,38400 console=tty1" --update-kernel=/boot/vmlinuz-5.11.16-300.fc34.x86_64
The first command specifies the baud rate, console forwarding for systemd
, what console to use (tty1
) and on what kernel such changes should be applied.
# grubby --set-default=/boot/vmlinuz-5.11.16-300.fc34.x86_64
The second command ensures the specified kernel is going to be loaded by default on next reboot.
For instructions on how to enable serial consol in GRUB 2 for baremetal machines, see Using GRUB via a serial line.