|
|
(100 intermediate revisions by 13 users not shown) |
Line 1: |
Line 1: |
| {{autolang|base=yes}} | | {{autolang|base=yes}} |
| = Introduction = | | = 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 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. | | GRUB 2 has replaced GRUB version 0.9x, which has become GRUB Legacy. Upstream refers to GRUB 2 as just GRUB. |
|
| |
|
| 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.
| | GRUB 2 is the bootloader used on x86_64 systems, and on aarch64 if UEFI firmware is also used. |
|
| |
|
| = Tasks / Common issues = | | = Changing kernel command-line parameters with <code>grubby</code> = |
|
| |
|
| == Updating GRUB 2 configuration on BIOS systems ==
| | The <code>grubby</code> 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. |
|
| |
|
| The grub2 packages contain commands for installing a bootloader and for creating a bootloader configuration file.
| | Following are some of the selected illustrations of <code>grubby</code> usage: |
|
| |
|
| grub2-install will install the bootloader - usually in the MBR, in free unpartioned space, and as files in /boot. The bootloader is installed with something like:
| | * To add one kernel parameter to a single boot entry: |
| | <pre># grubby --args=<NEW_PARAMETER> --update-kernel=/boot/vmlinuz-5.11.14-300.fc34.x86_64</pre> |
|
| |
|
| <pre>grub2-install /dev/sda</pre> | | * To add multiple kernel parameters to a single boot entry: |
| | <pre># grubby --args="<NEW_PARAMETER1> <NEW_PARAMETER2 <NEW_PARAMETER_n>" --update-kernel=/boot/vmlinuz-5.11.14-300.fc34.x86_64</pre> |
|
| |
|
| grub2-mkconfig will create a new configuration based on the currently running system, what is found in /boot, what is set in /etc/default/grub, and the customizable scripts in /etc/grub.d/ . A new configuration file is created with:
| | * To add one kernel parameter to all currently existing and future boot entries: |
| | <pre># grubby --args=<NEW_PARAMETER> --update-kernel=ALL</pre> |
|
| |
|
| <pre>grub2-mkconfig -o /boot/grub2/grub.cfg</pre> | | * To remove one kernel parameter from all currently existing and future boot entries: |
| | <pre># grubby --remove-args=<PARAMETER_TO_REMOVE> --update-kernel=ALL</pre> |
|
| |
|
| The configuration format has evolved over time, and a new configuration file might be slightly incompatible with the old bootloader. It is thus often/always a good idea to run grub2-install before grub2-mkconfig for some reason is run.
| | * To set the default kernel: |
| | <pre># grubby --set-default=/boot/vmlinuz-5.11.12-300.fc34.x86_64</pre> |
|
| |
|
| The Fedora installer, anaconda, will run these grub2 commands and there is usually no reason to run them manually.
| | = Updating the GRUB configuration file = |
|
| |
|
| It is generally safe to directly edit /boot/grub2/grub.cfg in Fedora. 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. (Other distributions, in particular Debian and Debian-derived distributions provide a software patch that adds an {{command|update-grub}} command which is neither included nor needed in Fedora.) Manual changes might however be overwritten with grub2-mkconfig next time the system is upgraded with anaconda. Some customizations can be placed in /etc/grub.d/40_custom or /boot/grub2/custom.cfg and will survive running grub2-mkconfig.
| | The GRUB configuration file is located at <code>/boot/grub2/grub.cfg</code> and is intended to be a static file that does not need updating. In case of disk replacement, or installation of another Linux distribution, <code>/boot/grub2/grub.cfg</code> should be updated. Use the following commands: |
|
| |
|
| == Updating GRUB 2 configuration on UEFI systems ==
| | <code>sudo grub2-mkconfig -o /etc/grub2.cfg</code> |
|
| |
|
| To install or fix GRUB 2 on a UEFI system on Fedora 18 or newer, you need to do four things:
| | <code>sudo grub2-mkconfig -o /etc/grub2-efi.cfg</code> |
|
| |
|
| === Create an ESP ===
| | <code>sudo grub2-mkconfig -o /boot/grub2/grub.cfg</code> - Legacy boot method for grub update. |
|
| |
|
| UEFI firmware, in general, likes to boot from an EFI System Partition on a disk with a GPT label. In <code>gdisk</code>, it looks something like this:
| | These commands use information provided by the <code>os-prober</code> utility to add entries for other Linux distributions and Windows. |
|
| |
|
| <pre>
| | {{admon/note|Refrain from using `grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg` going forward. This is a valid location on Fedora 33 and earlier. However on Fedora 34 and later, it is a small stub file that merely forwards to `/boot/grub2/grub.cfg`. See the [https://fedoraproject.org/wiki/GRUB_2#Reinstalling_GRUB Reinstalling GRUB] section if you have accidentally overwritten this file.|}} |
| Number Start (sector) End (sector) Size Code Name
| |
| 1 2048 264191 128.0 MiB EF00 EFI System
| |
| </pre>
| |
| | |
| That partition should be formatted as FAT. If in doubt, FAT32 is a good dialect of FAT to choose.
| |
| | |
| Fedora expects this partition to be mounted at <code>/boot/efi</code>. | |
|
| |
|
| === Install the bootloader files === | | = I have a `grub>` prompt! Now what? = |
|
| |
|
| If you don't already have the relevant packages installed, do for Fedora 22 and later versions with [[dnf|DNF]] or with YUM for older Fedora releases: | | If you are stuck at a `grub>` prompt, use a rescue mode to repair the already installed operating system. You can reach the rescue mode on any Fedora edition, spin of Network Installer, or DVD Installer. |
|
| |
|
| <pre>dnf install grub2-efi grub2-efi-modules shim
| | 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]. |
| yum install grub2-efi grub2-efi-modules shim</pre>
| |
|
| |
|
| If you do, then try:
| | After completing steps specified in the previous link, run the following command to mount the root partition: |
|
| |
|
| <pre>dnf reinstall grub2-efi grub2-efi-modules shim | | <pre># chroot /mnt/sysimage</pre> |
| yum reinstall grub2-efi grub2-efi-modules shim</pre>
| |
|
| |
|
| instead.
| | Next, update the GRUB configuration file as described in the [https://fedoraproject.org/wiki/GRUB_2#Updating_the_GRUB_configuration_file Updating the GRUB configuration file] section. Afterwards, continue with the section below for firmware specific instructions on [https://fedoraproject.org/wiki/GRUB_2#Reinstalling_GRUB Reinstalling GRUB]. |
|
| |
|
| Make sure that /boot/efi is mounted when you do this.
| | = Reinstalling GRUB = |
|
| |
|
| This installs the signed shim and the GRUB 2 binary.
| | GRUB comes in two flavors, BIOS GRUB and UEFI GRUB. The instructions on reinstalling GRUB depend on the firmware type. Systems with UEFI firmware have their GRUB RPM packages updated, which in turn updates the bootloader installed on the EFI System volume. |
|
| |
|
| === Create a GRUB 2 configuration === | | == Discovering the firmware type == |
|
| |
|
| GRUB 2 looks for its configuration in <code>/boot/efi/EFI/fedora/grub.cfg</code>. For newly installed kernels to work, <code>grubby</code> expects <code>/etc/grub2-efi.cfg</code> to be a symlink to the real grub.cfg (i.e. <code>/boot/efi/EFI/fedora/grub.cfg</code>).
| | To discover what firmware your machine uses, run the following command: |
|
| |
|
| If you already have a grub 2 EFI config file, you should be okay. If not, grub2-mkconfig can help, but your mileage may vary.
| | <pre># [ -d /sys/firmware/efi ] && echo UEFI || echo BIOS</pre> |
|
| |
|
| {{admon/caution|grub2-install shouldn't be used on EFI systems. The grub2-efi package installs a prebaked grubx64.efi on the EFI System partition, which looks for grub.cfg on the ESP in /EFI/fedora/ whereas the grub2-install command creates a custom grubx64.efi, deletes the original installed one, and looks for grub.cfg in /boot/grub2/.}}
| | The output returns only UEFI or BIOS, depending on the firmware your machine runs. |
|
| |
|
| === Create a boot menu entry === | | == Instructions for UEFI-based systems == |
|
| |
|
| TL;DR: This should happen automatically. If it doesn't, read on.
| | * Learn what firmware your machine is running. See [https://fedoraproject.org/wiki/GRUB_2#Discovering_the_firmware_type Discovering the firmware type] section. |
|
| |
|
| When you power on your system, your firmware will look for EFI variables that tell it how to boot. If you're already booted in EFI mode and EFI runtime services are working correctly, you can configure your boot menu with <code>efibootmgr</code>. If not, you'll have to bootstrap the process.
| | * Systems with UEFI firmware have the shim and GRUB RPM packages updated, which in turn updates the bootloader files found on the EFI System volume. Reasons for reinstallation include troubleshooting early boot problems, and following inadvertent use of the `grub2-install` command, which results in an unsupported configuration on UEFI systems. |
| | |
| Fortunately, <code>shim</code> can help you bootstrap. The EFI program <code>/boot/efi/EFI/BOOT/fallback.efi</code> will look for files called <code>BOOT.CSV</code> in your ESP and will add boot entries corresponding to them, '''if such entries do not already appear to exist'''. <code>shim</code> provides a <code>BOOT.CSV</code> file that will add an entry for <code>grub2-efi</code> for you. So just using the EFI Shell to invoke <code>fallback.efi</code> should do the trick. You can do this with commands like:
| |
|
| |
|
| | * Remove the following files: |
| <pre> | | <pre> |
| > fs0:
| | # rm /boot/efi/EFI/fedora/grub.cfg |
| > cd EFI\BOOT
| | # rm /boot/grub2/grub.cfg |
| > fallback.efi
| |
| </pre> | | </pre> |
|
| |
|
| If you have no boot entries at all, then just booting off your disk in UEFI mode should automatically invoke <code>/boot/efi/EFI/BOOT/BOOTX64.EFI</code>, which will, in turn, invoke <code>fallback.efi</code>.
| | * Reinstall the following packages: |
| | | <pre># dnf reinstall shim-* grub2-efi-* grub2-common</pre> |
| If you already have incorrect boot entries, you'll either need to delete them or to modify <code>BOOT.CSV</code> to create new entries with different names.
| |
| | |
| == Adding Other operating systems to the GRUB 2 menu ==
| |
| | |
| 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 ==
| |
| | |
| {{admon/warning|Some parts of this section is wrong or outdated for F17 and later releases. | <s>Be also aware of [[https://bugzilla.redhat.com/show_bug.cgi?id=768106 Bug 768106 - grubby does not support grub2 set default="${saved_entry}" and replaces with "0"]].</s> version grubby-8.28-1.fc19 has fixed issues with "Default Menuentry" as noted in the linked bug-report|}}
| |
| | |
| Due to <code>grub2-mkconfig</code> (and os-prober) we cannot predict the order of the entries in <code>/boot/grub2/grub.cfg</code>, so we set the default by name/title instead.
| |
| | |
| Open <code>/etc/default/grub</code> and ensure this line exists:
| |
| | |
| <pre>GRUB_DEFAULT=saved</pre> | |
| | |
| and ensure this line not exists:
| |
| | |
| <pre>GRUB_SAVEDEFAULT=true</pre>
| |
| | |
| or ensure this line exists:
| |
| | |
| <pre>GRUB_SAVEDEFAULT=false</pre>
| |
| | |
| {{admon/note|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 <code>grub.cfg</code> by running: <pre>grub2-mkconfig -o /boot/grub2/grub.cfg</pre>
| |
| | |
| Now list all possible menu entries
| |
| <pre>grep -P "submenu|^menuentry" /boot/grub2/grub.cfg | cut -d "'" -f2</pre>
| |
| | |
| Now set the desired default menu entry <pre>grub2-set-default "<submenu title><menu entry title>"</pre>
| |
| | |
| Verify the default menu entry <pre>grub2-editenv list</pre>
| |
| | |
| {{admon/note|Note|The above method fails to work on some F20 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.}}
| |
|
| |
|
| {{admon/note|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.}} | | {{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> RPM packages. By reinstalling those packages, the bootloaders are reinstalled to their proper location in <code>/boot/efi/</code> on the EFI System volume. }} |
|
| |
|
| If you understand the risks involved and still want to directly modify /boot/grub2/grub.cfg, here's how you can do it:
| | {{admon/note|The removal of the two `grub.cfg` files will trigger a script in `grub2-common` to recreate these files.|}} |
|
| |
|
| Edit /boot/grub2/grub.cfg, and change the line
| | == Instructions for BIOS-based systems == |
|
| |
|
| {{admon/caution|This is not the recommended method|This will not survive grub2-mkconfig. It might not even survive a kernel update.}}
| | * Learn what firmware your machine is running. See [https://fedoraproject.org/wiki/GRUB_2#Discovering_the_firmware_type Discovering the firmware type] section. |
|
| |
|
| <pre>
| | * Systems with the BIOS firmware have the GRUB RPM packages updated. However, the installed or embedded bootloader is never updated automatically. It is a good idea to update it between Fedora release versions. |
| set default="0"
| |
| </pre>
| |
|
| |
|
| to
| | * Find the device node the <code>/boot/</code> directory is located on: |
| <pre> | | <pre> |
| set default="5"
| | # mount | grep "/boot " |
| | /dev/sda4 on /boot type ext4 (rw,relatime,seclabel) |
| </pre> | | </pre> |
|
| |
|
| == Encountering the dreaded GRUB 2 boot prompt ==
| | The device node is <code>/dev/sda4</code>. |
| {{admon/tip|XFS and LVM Note|Since recent versions of Fedora and even RHEL/CentOS have started using ''xfs'' and ''lvm'' by default,
| |
| it's worth noting that these steps outlined here may need to be preceded with the necessary step to load the XFS and/or LVM module(s).}}
| |
|
| |
|
| | | * Reinstall the bootloader while specifying the device node without the number: |
| If improperly configured, GRUB 2 may fail to load and subsequently drop to a boot prompt. To address this issue, proceed as follows:
| |
| | |
| 0. Load the XFS and LVM modules
| |
| <pre> | | <pre> |
| insmod xfs
| | # grub2-install /dev/sda |
| insmod lvm
| | Installing for i386-pc platform. |
| | Installation finished. No error reported. |
| </pre> | | </pre> |
|
| |
|
| 1. List the drives which GRUB 2 sees:
| | = Enabling serial console in GRUB 2 = |
| <pre>
| |
| grub2> ls
| |
| </pre>
| |
|
| |
|
| 2. The output for a dos partition table /dev/sda with three partitons will look something like this:
| | 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>
| |
| (hd0) (hd0,msdos3) (hd0,msdos2) (hd0,msdos1)
| |
| </pre>
| |
|
| |
|
| 3. While the output for a gpt partition table /dev/sda with four partitions will look something like this:
| |
| <pre> | | <pre> |
| (hd0) (hd0,gpt4) (hd0,gpt3) (hd0,gpt2) (hd0,gpt1)
| | # 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> | | </pre> |
|
| |
|
| 4. With this information you can now probe each partition of the drive and locate your vmlinuz and initramfs files:
| | 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> | |
| ls (hd0,1)/
| |
| </pre> | |
| Will list the files on /dev/sda1. If this partition contains /boot, the output will show the full name of vmlinuz and initramfs.
| |
| | |
| 5. Armed with the location and full name of vmlinuz and initramfs you can now boot your system.
| |
| | |
| 5a. Declare your root partition:
| |
| <pre> | |
| grub> set root=(hd0,3)
| |
| </pre> | |
|
| |
|
| 5b. Declare the kernel you wish to use:
| |
| <pre> | | <pre> |
| grub> linux (hd0,1)/vmlinuz-3.0.0-1.fc16.i686 root=/dev/sda3 rhgb quiet selinux=0
| | # grubby --set-default=/boot/vmlinuz-5.11.16-300.fc34.x86_64 |
| # NOTE : add other kernel args if you have need of them
| | </pre> |
| # NOTE : change the numbers to match your system | |
| </pre>
| |
| | |
| 5c. Declare the initrd to use:
| |
| <pre>
| |
| grub> initrd (hd0,1)/initramfs-3.0.0-1.fc16.i686.img
| |
| # NOTE : change the numbers to match your system
| |
| </pre>
| |
| | |
| 5d. Instruct GRUB 2 to boot the chosen files:
| |
| <pre>
| |
| grub> boot
| |
| </pre>
| |
| | |
| 6. After boot, open a terminal.
| |
| | |
| 7. Issue the grub2-mkconfig command to re-create the grub.cfg file grub2 needed to boot your system:
| |
| <pre>
| |
| grub2-mkconfig -o /boot/grub2/grub.cfg
| |
| </pre>
| |
| | |
| 8. Issue the grub2-install command to install grub2 to your hard drive and make use of your config:
| |
| <pre>
| |
| grub2-install --boot-directory=/boot /dev/sda
| |
| # Note: your drive may have another device name. Check for it with mount command output.
| |
| </pre>
| |
| | |
| == Other GRUB 2 issues ==
| |
| | |
| ''' Absent Floppy Disk ''': It has been reported by some users that GRUB 2 may fail to install on a partition's boot sector if the computer floppy controller is activated in BIOS without an actual floppy disk drive being present. A possible workaround is to run (post OS install) from rescue mode:
| |
| | |
| <pre>
| |
| grub2-install <target device> --no-floppy
| |
| </pre>
| |
| | |
| == Setting a password for interactive edit mode ==
| |
| | |
| If you wish to password-protect GRUB2's interactive edit mode '''but''' you do not want to require users to enter a password to do a plain, simple, ordinary boot, create /etc/grub.d/01_users with the following lines:
| |
| | |
| <pre>
| |
| cat << EOF
| |
| set superusers="root"
| |
| export superusers
| |
| password root secret
| |
| EOF
| |
| </pre>
| |
| | |
| To apply your changes run:
| |
| | |
| <pre>
| |
| grub2-mkconfig -o /boot/grub2/grub.cfg
| |
| </pre>
| |
| | |
| You can encrypt the password by using pbkdf2. Use grub2-mkpasswd-pbkdf2 to encrypt the password, then replace the password line with:
| |
| | |
| <pre>
| |
| pbkdf2 root grub.pbkdf2.sha512.10000.1B4BD9B60DE889A4C50AA9458C4044CBE129C9607B6231783F7E4E7191D8254C0732F4255178E2677BBE27D03186E44815EEFBAD82737D81C87F5D24313DDDE7.E9AEB53A46A16F30735E2558100D8340049A719474AEEE7E3F44C9C5201E2CA82221DCF2A12C39112A701292BF4AA071EB13E5EC8C8C84CC4B1A83304EA10F74
| |
| </pre>
| |
| | |
| More details can be found at [https://help.ubuntu.com/community/Grub2/Passwords Ubuntu Help: GRUB2 Passwords].
| |
| | |
| Starting from atleast Fedora 21, the <code>--md5pass</code> kickstart option must be set using output from grub2-mkpasswd-pbkdf2.
| |
| | |
| == Using old graphics modes in bootloader ==
| |
| Terminal device is chosen with GRUB_TERMINAL; additional quote from http://www.gnu.org/software/grub/manual/grub.html#Simple-configuration
| |
| | |
| <code>
| |
| 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.
| |
| </code> | |
| | |
| The default in Fedora is gfxterm and to get the legacy graphics modes you need to set GRUB_TERMINAL to right variable from the description above in /etc/default/grub
| |
| | |
| == 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)
| |
| | |
| <pre>
| |
| 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"
| |
| </pre>
| |
| | |
| And re-generate grub
| |
| | |
| <code>
| |
| grub2-mkconfig -o /boot/grub2/grub.cfg
| |
| </code>
| |
|
| |
|
| = Further Reading =
| | The second command ensures the specified kernel is going to be loaded by default on next reboot. |
|
| |
|
| * http://www.gnu.org/software/grub/manual/grub.html
| | 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]. |
| * [[Features/Grub2]]
| |
| * [[Anaconda/Features/Grub2Migration]]
| |
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. Upstream refers to GRUB 2 as just GRUB.
GRUB 2 is the bootloader used on x86_64 systems, and on aarch64 if UEFI firmware is also used.
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 the GRUB configuration file
The GRUB configuration file is located at /boot/grub2/grub.cfg
and is intended to be a static file that does not need updating. In case of disk replacement, or installation of another Linux distribution, /boot/grub2/grub.cfg
should be updated. Use the following commands:
sudo grub2-mkconfig -o /etc/grub2.cfg
sudo grub2-mkconfig -o /etc/grub2-efi.cfg
sudo grub2-mkconfig -o /boot/grub2/grub.cfg
- Legacy boot method for grub update.
These commands use information provided by the os-prober
utility to add entries for other Linux distributions and Windows.
Refrain from using grub2-mkconfig -o /boot/efi/EFI/fedora/grub.cfg
going forward. This is a valid location on Fedora 33 and earlier. However on Fedora 34 and later, it is a small stub file that merely forwards to /boot/grub2/grub.cfg
. See the Reinstalling GRUB section if you have accidentally overwritten this file.
I have a grub>
prompt! Now what?
If you are stuck at a grub>
prompt, use a rescue mode to repair the already installed operating system. You can reach the rescue mode on any Fedora edition, spin of Network Installer, or DVD Installer.
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
Next, update the GRUB configuration file as described in the Updating the GRUB configuration file section. Afterwards, continue with the section below for firmware specific instructions on Reinstalling GRUB.
Reinstalling GRUB
GRUB comes in two flavors, BIOS GRUB and UEFI GRUB. The instructions on reinstalling GRUB depend on the firmware type. Systems with UEFI firmware have their GRUB RPM packages updated, which in turn updates the bootloader installed on the EFI System volume.
Discovering the firmware type
To discover what firmware your machine uses, run the following command:
# [ -d /sys/firmware/efi ] && echo UEFI || echo BIOS
The output returns only UEFI or BIOS, depending on the firmware your machine runs.
Instructions for UEFI-based systems
- Systems with UEFI firmware have the shim and GRUB RPM packages updated, which in turn updates the bootloader files found on the EFI System volume. Reasons for reinstallation include troubleshooting early boot problems, and following inadvertent use of the
grub2-install
command, which results in an unsupported configuration on UEFI systems.
- Remove the following files:
# rm /boot/efi/EFI/fedora/grub.cfg
# rm /boot/grub2/grub.cfg
- Reinstall the following packages:
# dnf reinstall shim-* grub2-efi-* grub2-common
Do not use the grub2-install
command on UEFI systems. On those systems, bootloaders are in the shim
and grub-efi
RPM packages. By reinstalling those packages, the bootloaders are reinstalled to their proper location in /boot/efi/
on the EFI System volume.
The removal of the two grub.cfg
files will trigger a script in grub2-common
to recreate these files.
Instructions for BIOS-based systems
- Systems with the BIOS firmware have the GRUB RPM packages updated. However, the installed or embedded bootloader is never updated automatically. It is a good idea to update it between Fedora release versions.
- Find the device node the
/boot/
directory is located on:
# 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.
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.