keepcalculator

06 Numbers and Powers

UEFI and GRUB: How They Work Together

Card No. 06·38830 · Updated · Standard formula, shown below

This guide explains how UEFI (Unified Extensible Firmware Interface) and GRUB (GRand Unified Bootloader) cooperate to start your Linux system. You’ll learn what each component does, how they hand off control, and how to configure and troubleshoot the boot process. No prior deep knowledge is required, but basic familiarity with Linux and terminal commands helps.

What You’ll Need

  • A computer with UEFI firmware (most systems from 2012 onward).
  • A Linux distribution installed in UEFI mode (e.g., Ubuntu, Fedora, Arch).
  • Root or sudo access to inspect and edit boot configuration.
  • Optional: a live USB for recovery if something goes wrong.

Step-by-Step

  1. Understand the boot flow. When you power on, UEFI firmware initializes hardware, then reads a list of boot entries stored in NVRAM. Each entry points to an EFI executable file on the EFI system partition (ESP). The first valid entry is executed; in a typical Linux setup, that’s the GRUB bootloader (e.g., \EFI\ubuntu\shimx64.efi or \EFI\GRUB\grubx64.efi).
  2. Identify your firmware mode. Check if you’re booting in UEFI mode by running [ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS" in a terminal. If it prints UEFI, you’re on the right track.
  3. Locate the EFI System Partition. Run lsblk -f or blkid to find the partition with type vfat (FAT32) and usually a mount point of /boot/efi. This is where GRUB’s EFI files live.
  4. Examine GRUB’s configuration. The main config is /boot/grub/grub.cfg (or /boot/grub2/grub.cfg on some distros). It’s generated by scripts and should not be edited directly. Instead, edit /etc/default/grub and files in /etc/grub.d/.
  5. Understand GRUB’s role. GRUB reads its config, displays a menu (if configured), and then loads the Linux kernel and initramfs from the root or boot partition. It passes control to the kernel, which then mounts the real root filesystem.
  6. Check the boot entries. Run efibootmgr -v to list UEFI boot entries. You should see an entry for your distro, e.g., “ubuntu” pointing to \EFI\ubuntu\shimx64.efi. If it’s missing, you can add it with efibootmgr -c -d /dev/sda -p 1 -L "Linux" -l \\EFI\\ubuntu\\shimx64.efi (adjust device and partition).
  7. Reinstall or update GRUB if needed. On Debian/Ubuntu: sudo grub-install (it will detect EFI and install to the ESP). Then run sudo update-grub to regenerate the config. On Fedora: sudo grub2-mkconfig -o /boot/grub2/grub.cfg.
  8. Test with a reboot. After any change, reboot and see if the menu appears and the system boots. If you have multiple OSes, GRUB should list them.

Common Mistakes

  • Editing grub.cfg directly: Changes are overwritten on the next update. Always edit /etc/default/grub and run the update command.
  • Missing ESP mount: If /boot/efi isn’t mounted, GRUB installation fails. Mount it first: mount /dev/sda1 /boot/efi (use your ESP device).
  • BIOS vs UEFI mismatch: Installing GRUB for BIOS firmware on a UEFI system (or vice versa) causes boot issues. Ensure you’re in the correct mode when installing.
  • Secure Boot not handled: On many systems, you need shim (a signed bootloader) or disable Secure Boot. If you get “Invalid signature” errors, either enable shim or disable Secure Boot in firmware settings.
  • Wrong partition for EFI: The ESP must be FAT32 and have the EFI system partition type (ef00 in gdisk). Using NTFS or ext4 will fail.

Tips

  • Use efibootmgr to manage boot order. For example, sudo efibootmgr -o 0000,0001 sets the order.
  • If you want a hidden GRUB menu, set GRUB_TIMEOUT=0 in /etc/default/grub and run update-grub. Hold Shift (BIOS) or press Esc (UEFI) during boot to force it.
  • For dual-boot, install GRUB last so it detects Windows and adds an entry automatically.
  • Backup your grub.cfg before major changes: sudo cp /boot/grub/grub.cfg /boot/grub/grub.cfg.bak.
  • If you use LVM or LUKS, make sure the initramfs includes the necessary modules; GRUB itself doesn’t need them.

Troubleshooting

  • System boots straight to Windows: Use efibootmgr to change boot order, or press the boot menu key (F12, F2, etc.) during startup and select your Linux entry.
  • GRUB menu doesn’t appear: Try holding Shift or pressing Esc repeatedly at boot. If that fails, check GRUB_TIMEOUT in the config; it might be set to 0.
  • Error: “no such partition” or “unknown filesystem”: This often means GRUB can’t find its files. Boot from a live USB, chroot into your system, and reinstall GRUB with grub-install and update the config.
  • Secure Boot violation: Either disable Secure Boot in firmware or ensure you’re using shim. On some systems, you may need to enroll a key (MOK) for custom kernels.
  • After a Windows update, Linux disappears: Windows may reset the boot order. Use efibootmgr to reorder, or boot from a live USB and reinstall GRUB.
  • GRUB shows “Minimal BASH-like line editing”: This means the config is missing or unreadable. Use the ls command to find partitions, then manually set root and configfile, e.g., set root=(hd0,gpt2) and configfile /boot/grub/grub.cfg.

Frequently Asked Questions

What is the difference between UEFI and BIOS?

UEFI is a modern firmware interface that supports larger disks, faster boot, secure boot, and a more flexible boot process. BIOS is the older legacy system with 16-bit code and limited features.

Can I use GRUB without UEFI?

Yes, GRUB supports both BIOS and UEFI. In BIOS mode, GRUB installs its core image to the Master Boot Record (MBR) of the disk.

Why does GRUB need an EFI System Partition?

UEFI firmware can only execute files from a FAT32 partition with a specific type. The ESP stores the GRUB EFI executable and other bootloaders.

How do I change the default GRUB boot entry?

Edit /etc/default/grub and set GRUB_DEFAULT to the menu entry number (starting from 0) or a saved entry. Then run update-grub.

What is shim and do I need it?

Shim is a small signed bootloader that allows GRUB to work with Secure Boot. If Secure Boot is enabled, you need shim or a signed GRUB binary.

Why does GRUB show a black screen after boot?

This can be due to graphics drivers or a missing framebuffer. Try adding GRUB_GFXMODE=text in /etc/default/grub and update, or use the nomodeset kernel parameter.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →