GRUB 2.2: Linux Bootloader Concepts, Configuration, and Recovery
Learn how GRUB 2.2 fits into the Linux boot process, how configuration is generated, how to pass kernel parameters, and how to recover BIOS and UEFI systems safely.
GRUB, the GNU GRand Unified Bootloader, is software that starts after firmware initialization and loads an operating system. It can present a menu of Linux kernels and other operating systems, pass options to the Linux kernel, and provide recovery choices when a normal boot fails.
This lesson uses “GRUB 2.2” as the topic label for the modern GRUB 2 family. Distribution packages and documentation may call it GRUB 2, grub2, or simply grub. Exact commands, paths, and features depend on the distribution and firmware mode.
What GRUB Does
A bootloader is software that selects and loads an operating system kernel. GRUB sits between firmware and the Linux startup process:
- BIOS or UEFI firmware initializes hardware and selects a boot target.
- Firmware starts GRUB or a GRUB EFI executable.
- GRUB reads its configuration and displays boot choices.
- GRUB loads the Linux kernel and initramfs, then passes the kernel command line.
- The kernel starts early userspace, discovers storage, and mounts the root filesystem.
The kernel is the core of the operating system. The initramfs is a temporary early-userspace filesystem containing tools and drivers needed to find and mount the real root filesystem, the filesystem eventually mounted as /.
- Boot Linux normally.
- Select an older kernel after a kernel or driver update.
- Choose a second operating system in a dual-boot installation.
- Pass diagnostic or recovery parameters to the kernel.
- Start a recovery entry or emergency target.
GRUB 2 Compared with Legacy GRUB
GRUB 2 is the modern GRUB architecture used by most Linux distributions. It differs significantly from legacy GRUB, sometimes called GRUB Legacy. In GRUB 2, the visible menu is normally generated from source settings and scripts rather than maintained as one hand-edited menu file.
| Feature | GRUB 2 | Legacy GRUB |
|---|---|---|
| Configuration style | Generated configuration assembled from defaults and scripts | Usually maintained in a manually edited configuration file |
| Common configuration source | /etc/default/grub and /etc/grub.d/ | Often a legacy menu.lst or similar file |
| Kernel discovery | Distribution scripts commonly find installed kernels automatically | Entries were commonly written manually |
| Modular design | Uses loadable modules and supports BIOS and UEFI targets | Older architecture with different module and installation behavior |
Do not assume that a command or path from one GRUB generation applies to the other. Also confirm whether your distribution uses /boot/grub or /boot/grub2.
The Boot Process: BIOS and UEFI
BIOS is a legacy firmware environment. It commonly reads initial boot code from a disk's boot area and transfers control to GRUB. BIOS installations must place GRUB in a location that the firmware and partition layout support. With GPT partitioning, a BIOS Boot Partition may be required for embedded boot components.
UEFI is a modern firmware interface. It starts an EFI executable from an EFI System Partition (ESP), a small FAT-formatted partition that stores boot files. A UEFI GRUB installation normally places an EFI executable on the ESP and may also create a firmware boot entry in nonvolatile firmware storage.
| Aspect | BIOS | UEFI |
|---|---|---|
| Firmware startup method | Firmware transfers control to disk boot code | Firmware launches an EFI executable |
| Partitioning considerations | Disk boot area; GPT systems may need a BIOS Boot Partition | EFI System Partition, normally FAT-formatted |
| GRUB installation target | Appropriate whole-disk BIOS target | Appropriate EFI target and mounted ESP |
| Boot file location | Boot code in disk boot areas plus GRUB files under /boot | EFI files on the ESP plus GRUB files under /boot or a distribution-specific location |
| Firmware boot-entry management | Usually no UEFI NVRAM entry | Firmware entries may need to be created or repaired |
| Typical repair concern | Correct disk target and BIOS-compatible partition layout | Correct ESP mount, EFI target, firmware entry, and Secure Boot policy |
Firmware mode must match the repair method. If the installed system was installed in UEFI mode, boot rescue media in UEFI mode; if it was installed for BIOS, use the BIOS-compatible repair path. Check the layout with tools such as lsblk, blkid, and the output of mount before changing boot files.
GRUB Files and Configuration Layout
The generated main configuration file is commonly /boot/grub/grub.cfg on Debian-family systems and /boot/grub2/grub.cfg on some Red Hat-family systems. This file contains generated menu definitions and commands.
Do not normally edit grub.cfg directly. Package updates, kernel installation, and configuration regeneration can overwrite manual edits. Instead, change the distribution's source settings and regenerate the file.
/etc/default/grubcommonly contains global settings such as timeout, default entry, menu visibility, and extra kernel parameters./etc/grub.d/commonly contains executable generator scripts. Their numeric prefixes influence ordering.grub.cfgis the generated result consumed by GRUB at boot.- Kernel and initramfs files normally reside in
/boot. - The ESP is mounted at a path such as
/boot/efion many UEFI installations, but the mount point is not universal.
| Distribution family | Defaults file | Script directory | Generated configuration path | Generation command |
|---|---|---|---|---|
| Debian and Ubuntu family | /etc/default/grub | /etc/grub.d/ | Commonly /boot/grub/grub.cfg | sudo update-grub |
| Fedora and Red Hat family | Often /etc/default/grub | Often /etc/grub.d/ | Commonly /boot/grub2/grub.cfg | Often grub2-mkconfig with a distribution-specific output path |
| Arch family | Commonly /etc/default/grub | Commonly /etc/grub.d/ | Often /boot/grub/grub.cfg | Often grub-mkconfig -o ... |
| Variation | Verify installed package documentation and existing mounts; names, paths, wrappers, and detection behavior can differ. | |||
Menu Entries and Boot Selection
A menuentry block represents one bootable choice. It normally identifies a kernel, an initramfs, and the options passed to the kernel. A submenu groups related choices, such as older kernels and recovery entries. Distribution scripts commonly create these entries automatically when kernels are installed.
GRUB_DEFAULT controls the default choice. It may refer to a numeric menu position, a menu identifier, or a saved selection, depending on the distribution's syntax. GRUB_TIMEOUT controls how long the menu waits. GRUB_TIMEOUT_STYLE can show a menu, hide it, or display it only after a key is pressed. Saved selections require compatible saved-entry settings and should be tested carefully.
At boot, select an older kernel from the main menu or an Advanced Options submenu. Recovery entries may start a restricted target or provide repair tools. To inspect or temporarily modify an entry, highlight it and use the edit control shown by the menu. A temporary edit lasts for that boot only.
When operating-system detection is enabled and supported, GRUB can scan for another installation and generate a chainloading entry. Detection may be disabled for security or policy reasons, unsupported by the installed packages, or unable to access the other system's boot files.
Kernel Command-Line Parameters
The kernel command line is the set of parameters GRUB passes to the kernel. Parameters are separated by spaces and are interpreted by the kernel, initramfs, drivers, or the early userspace system.
| Parameter | Purpose | When to use it | Persistence | Caution |
|---|---|---|---|---|
quiet | Reduces routine kernel messages | Cleaner normal boots | Persistent if stored in defaults | Remove it while diagnosing boot messages |
splash | Requests a graphical splash screen | Desktop presentation | Persistent if stored in defaults | Can hide useful diagnostic output |
nomodeset | Temporarily avoids normal graphics mode-setting | Testing a black screen or graphics-driver issue | Temporary unless saved | May reduce display features and is not a general graphics fix |
systemd.unit= | Requests a systemd target or unit | Starting a restricted or diagnostic target | Usually temporary during testing | Use a valid target for the installed system |
single | Requests single-user-style recovery behavior | Some recovery scenarios | Usually temporary | Behavior varies with distribution and systemd configuration |
root= | Identifies the root filesystem | Root-device troubleshooting | Persistent or temporary | Use the correct UUID, label, or device scheme |
ro and rw | Request read-only or read-write root mounting | Recovery and filesystem diagnosis | Usually entry-dependent | Do not write to a damaged filesystem without assessing its condition |
init= can request a particular initial userspace program, but it is an advanced recovery parameter. An incorrect value can prevent startup. Validate every parameter against the installed distribution and system design, especially when encryption, RAID, LVM, or unusual storage drivers are involved.
Temporary Versus Persistent Changes
Editing a menu entry at boot changes only that boot attempt. To make a change persistent, edit the appropriate source, commonly /etc/default/grub, then regenerate the configuration. Preserve at least one known-good boot path before removing entries or adding experimental parameters.
# Example source settings; edit the distribution defaults file, not grub.cfg
GRUB_TIMEOUT=5
GRUB_TIMEOUT_STYLE=menu
GRUB_DEFAULT=0
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
# Inspect commonly used active settings
grep -E '^(GRUB_DEFAULT|GRUB_TIMEOUT|GRUB_TIMEOUT_STYLE|GRUB_CMDLINE_LINUX)' /etc/default/grub
Safe Configuration Workflow
- Record the current firmware mode, disk layout, mount points, and known-good menu entry.
- Back up relevant configuration files and ensure bootable live or rescue media is available.
- Edit source settings with administrative privileges.
- Regenerate the configuration using the distribution's wrapper or generator.
- Review the generated output and confirm that a normal kernel, an older kernel, and any required recovery path remain available.
- Reboot during a maintenance window and test the intended entry.
sudo update-grub
On systems without that wrapper, a generic command may look like this, but the output path must be confirmed:
sudo grub-mkconfig -o /boot/grub/grub.cfg
Device names such as /dev/sda, /dev/nvme0n1, and partition identifiers are not interchangeable. Confirm the whole disk, partition, UUID, firmware mode, and separate /boot or ESP mounts before installing or repairing GRUB.
Installing and Repairing GRUB
Installing GRUB for BIOS and UEFI are different operations. A BIOS installation targets suitable disk boot code. A UEFI installation targets an EFI executable and requires the ESP to be mounted. Neither command should be treated as universal without checking the installed layout and distribution.
| Target | Illustration | Important verification |
|---|---|---|
| BIOS | sudo grub-install /dev/sdXsudo grub-mkconfig -o /boot/grub/grub.cfg | Identify the correct whole-disk device; do not append a partition number for a standard BIOS target. |
| UEFI | sudo grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUBsudo grub-mkconfig -o /boot/grub/grub.cfg | Mount the actual ESP, confirm architecture and bootloader identifier, and verify the firmware entry. |
A typical rescue workflow is:
- Boot live or rescue media in the same BIOS or UEFI mode as the installed system.
- Use
lsblk,blkid, and filesystem inspection to identify the installed root, separate/boot, and ESP. - Mount the root filesystem at a temporary path such as
/mnt, then mount separate boot filesystems beneath it. - Bind or mount
/dev,/dev/pts,/proc, and/sysas required by the distribution. - Enter the installed environment with
chroot. - Reinstall the correct BIOS or UEFI GRUB target, regenerate configuration, and inspect firmware entries when using UEFI.
- Exit, unmount cleanly, reboot, and test the menu.
sudo mount /dev/ROOT_PARTITION /mnt
sudo mount /dev/BOOT_PARTITION /mnt/boot
sudo mount /dev/EFI_SYSTEM_PARTITION /mnt/boot/efi
sudo mount --bind /dev /mnt/dev
sudo mount --bind /dev/pts /mnt/dev/pts
sudo mount -t proc proc /mnt/proc
sudo mount -t sysfs sys /mnt/sys
sudo chroot /mnt /bin/bash
Mount only partitions that exist in the target layout. The placeholder device names above must be replaced only after verification. In UEFI repair, firmware boot-entry repair may be necessary if the NVRAM entry was deleted or reset. Secure Boot policy can also affect whether a boot component is accepted.
GRUB Command Shell and Rescue Mode
The normal GRUB command shell is a relatively capable interactive environment. grub rescue is a more limited environment shown when GRUB cannot load normal modules or locate its configuration. The GRUB prefix is the location from which GRUB finds its configuration and modules.
lslists disks, partitions, and sometimes filesystem contents.setdisplays or changes variables such asrootandprefix.insmodloads a GRUB module, such asnormalor a filesystem driver.normalattempts to return to the standard menu.configfileloads a configuration file found on a selected filesystem.linuxloads a Linux kernel and accepts its command line.initrdloads an initramfs.bootstarts the loaded boot components.
ls
set
ls (hd0,gpt1)/
set root=(hd0,gpt2)
set prefix=(hd0,gpt2)/boot/grub
insmod normal
normal
Partition notation, module names, and directory locations vary. These commands are for discovery and temporary recovery, not a fixed repair recipe. Once the normal menu is reachable, permanently repair the installation from the installed system or rescue media.
| Environment | Typical symptom | Capabilities | Useful commands | Recommended next step |
|---|---|---|---|---|
| Normal boot menu | GRUB displays choices | Select kernels, recovery entries, and other systems | Menu controls and temporary editing | Try a known-good or older kernel |
| GRUB command shell | Interactive GRUB prompt | Filesystem discovery and manual loading | ls, set, insmod, linux, initrd, boot, normal | Locate the prefix, boot temporarily, then repair permanently |
grub rescue> | Missing prefix or modules | Limited filesystem and variable operations | ls, set, insmod, normal | Find the correct partition and use rescue media if needed |
| Live or rescue environment | Installed system does not start | Full Linux tools, mounting, chroot, package repair | lsblk, blkid, mount, chroot | Repair the installed bootloader and regenerate configuration |
Common Failure Modes and Diagnosis
No Bootable Device or Missing GRUB
Firmware may be using the wrong disk, boot mode, or boot entry. Disk replacement, partition changes, or a firmware reset can produce this symptom. Confirm whether the installation is BIOS or UEFI, inspect the disk layout, verify the ESP when applicable, and reinstall the matching GRUB target rather than using a copied command blindly.
The System Drops to grub rescue>
GRUB may have an incorrect prefix, missing modules, an unreadable filesystem, or a partition that was moved or reformatted. Use ls to inspect candidate partitions, identify the one containing the GRUB directory, set temporary root and prefix values, and try insmod normal followed by normal. Perform a permanent repair afterward.
Kernel Panic or Root Filesystem Failure
GRUB may load successfully while Linux fails to mount its root filesystem. Likely causes include an incorrect root= value, a damaged initramfs, or unavailable storage support for encryption, RAID, LVM, or a controller. Try an older kernel or recovery entry, compare its parameters with the failing entry, and use rescue media to verify UUIDs, storage configuration, and initramfs files.
Black Screen After Kernel Selection
A graphics driver or kernel mode-setting problem can prevent visible output. Temporarily remove quiet and splash to reveal messages. Where appropriate, test nomodeset for one boot. If an older kernel works, repair or update the graphics stack from the installed system.
Missing Dual-Boot Entry
Operating-system detection may be disabled, unsupported, unable to access the other system, or affected by incompatible BIOS and UEFI installation modes. Confirm that the other installation and its boot files are present, review the detection policy, regenerate the configuration, and inspect the generated entries. Firmware boot selection or a carefully designed chainloading entry may be appropriate in some layouts.
UEFI Starts Firmware Directly
The ESP may be missing, unmounted, damaged, or missing GRUB EFI files. The firmware NVRAM entry may also have been removed. Boot rescue media in UEFI mode, verify the ESP type and contents, reinstall the correct EFI target, inspect firmware boot entries, and check Secure Boot policy if boot components are rejected.
Security and Operations
Physical access to a GRUB menu can allow a person to edit kernel parameters, select recovery modes, or start another installed operating system. This can weaken local access controls, especially if disks are not encrypted.
GRUB supports password protection for administrative menu editing and selected commands. Password protection has limitations: it does not replace full-disk encryption, does not prevent firmware settings from being changed, and does not protect an attacker who can alter the disk or boot from external media. Secure Boot adds a UEFI verification layer by allowing firmware to trust signed boot components, but it must be planned together with the distribution's signed boot chain and any custom kernels or modules.
For production systems, back up configuration and important data, keep recovery media available, test changes on a noncritical system when possible, preserve a known-good kernel, and schedule bootloader work during a controlled maintenance window.
Practical Examples
Change the Menu Timeout
- Edit
/etc/default/gruband set a suitableGRUB_TIMEOUTand menu style. - Run the distribution's configuration generator, commonly
sudo update-grubon Debian and Ubuntu systems. - Review the generated configuration and reboot during a maintenance window.
Boot an Older Kernel
Open the GRUB menu, choose the older kernel directly or through Advanced Options, and test whether the system starts normally. If it works, investigate the newer kernel, driver, initramfs, or kernel parameters before making the older entry the permanent default.
Diagnose a Graphics Failure
Highlight the Linux entry, use the temporary edit control, remove quiet and splash, and add nomodeset when suitable. Boot once and use the result to determine whether graphics mode-setting is implicated. Do not save the parameter permanently until its effect is understood.
Recover from Live Media
Identify partitions, mount the installed root and any separate boot or ESP filesystems, bind the required virtual filesystems, enter the installed system with chroot, reinstall the correct firmware-specific GRUB target, regenerate the configuration, and verify the firmware entry before rebooting.
Exam-Ready Summary
- Firmware initializes hardware and starts GRUB; GRUB loads the kernel and initramfs.
- BIOS and UEFI use different boot mechanisms and repair targets.
- The UEFI EFI System Partition stores EFI boot files.
grub.cfgis generated output and should not normally be edited directly./etc/default/grubstores common global settings;/etc/grub.d/contains generator scripts.menuentryrepresents a boot choice;submenugroups choices.- Kernel parameters can be edited temporarily at boot or stored persistently in source configuration.
- A GRUB prompt indicates a problem locating modules, the prefix, or configuration; a kernel panic indicates a later Linux startup problem.
- Always confirm firmware mode, device names, partition layout, mounts, and recovery options before reinstalling GRUB.