Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

grub2-install

Install the GRUB 2 boot loader to a disk (BIOS systems) — used to repair a system that does not find its boot loader.

Level
Everyday Linux
Group
Kernel and hardware
Needs root
Yes
Package
grub2-tools

What it does

On BIOS systems, grub2-install /dev/vda writes the GRUB boot code to the start of the disk and the modules to /boot/grub2/. On UEFI systems with Secure Boot, do not use it: reinstall the packages grub2-efi-x64 and shim-x64 instead, which put the signed files in /boot/efi/EFI/redhat/.

After installing, create the config with grub2-mkconfig -o /boot/grub2/grub.cfg.

How to write it

grub2-install [OPTION]... DEVICE

Options 20

Most used

--target=TARGET
Platform: i386-pc (BIOS), x86_64-efi …
--boot-directory=DIR
Where /boot is (default /boot).
--efi-directory=DIR
The EFI system partition (UEFI).
--bootloader-id=ID
Name of the EFI folder and boot entry.
--removable
Install to the fallback path (removable media).
--recheck
Probe the devices again.
--force
Install even with warnings.
-v, --verbose
Verbose.
--modules=MODULES, --install-modules=MODULES
Modules to preload / install.
-d, --directory=DIR
Use images and modules from DIR.
--no-nvram
Do not change the UEFI boot entries.
--no-bootsector
Do not write the boot sector.
--uefi-secure-boot, --no-uefi-secure-boot
Secure Boot layout.
-s, --skip-fs-probe
Do not probe the file system.
--compress=no|xz|gz|lzo, --core-compress=xz|none|auto
Compression.
--fonts=, --locales=, --themes=, --locale-directory=DIR
Extra files.
-k, --pubkey=FILE
Check signatures with this key.
--disk-module=MODULE, --allow-floppy, --force-file-id, --no-rs-codes, --product-version=STRING, --sbat=FILE, --disable-shim-lock, --dtb=FILE, --label-*, --macppc-directory=DIR
Special settings.
-?, --help, --usage
Show help.
-V, --version
Show the version.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Reinstall GRUB on a BIOS disk

    grub2-install /dev/vda
    Installing for i386-pc platform.
    Installation finished. No error reported.

    The disk, not a partition.

  2. 2Then rebuild the config

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

    Menu entries come from BLS files.

  3. 3From a rescue disk

    chroot /mnt/sysroot
    grub2-install /dev/vda

    Inside the installed system.

  4. 4Is this BIOS or UEFI?

    [ -d /sys/firmware/efi ] && echo UEFI || echo BIOS

    Decides which repair to use.

  5. 5UEFI repair (instead of grub2-install)

    dnf reinstall -y grub2-efi-x64 shim-x64

    Signed files for Secure Boot.

  6. 6UEFI boot entries

    efibootmgr -v

    Check that "Red Hat Enterprise Linux" points to shimx64.efi.

  7. 7Both disks of a software RAID1

    grub2-install /dev/vda; grub2-install /dev/vdb

    The system boots even when one disk fails.

  8. 8Verbose run

    grub2-install -v /dev/vda 2>&1 | tail

    Find the reason of an error.

  9. 9Another boot folder

    grub2-install --boot-directory=/mnt/sysroot/boot /dev/vda

    Without chroot.

  10. 10Check the boot sector

    dd if=/dev/vda bs=512 count=1 2>/dev/null | strings | grep -i grub
    GRUB

    The boot code is there.

Exit codes

0Done.
1Error.