LinuxCommandLibrary

grub

Configure the bootloader

SYNOPSIS

grub-install [OPTION...] INSTALL_DEVICE
or for UEFI:
grub-install [OPTION...] --target=TARGET --efi-directory=EFI_DIR [--bootloader-id=ID]

PARAMETERS

INSTALL_DEVICE
    The target device (e.g., /dev/sda) onto which GRUB will be installed for BIOS systems.

--boot-directory=DIR
    Use DIR as the boot directory where GRUB files will be placed.

--efi-directory=DIR
    Specify the root directory of the EFI System Partition (ESP) for UEFI installations.

--target=TARGET
    Install GRUB for the specified platform (e.g., i386-pc for BIOS, x86_64-efi for UEFI).

--modules=MODULES
    Specify a comma-separated list of additional GRUB modules to install.

--recheck
    Probe a device again to refresh its information before installation.

--debug
    Print verbose debugging information during the installation process.

--version
    Print GRUB version information and exit.

--help
    Display a help message and exit.

DESCRIPTION

The GRUB (Grand Unified Bootloader) is the standard bootloader for most Linux distributions. It is responsible for loading the operating system kernel into memory from storage devices and passing control to it.

GRUB is highly configurable, supporting multiple operating systems (dual-booting), various file systems, and different architectures (BIOS, UEFI). While there isn't a single executable named "grub" that serves as a general-purpose command-line utility with diverse options, the term "grub command" often refers to the suite of utilities used to manage and configure the GRUB bootloader, or the interactive GRUB shell.

Key utilities include grub-install (for installing GRUB to a device), grub-mkconfig (for generating the main configuration file, grub.cfg), and grub-probe (for device mapping). The interactive GRUB shell (often encountered during boot issues) provides its own set of internal commands for manual booting or troubleshooting. This analysis primarily focuses on the common external utilities, particularly grub-install, which is central to GRUB deployment.

CAVEATS

The grub-install command is extremely powerful and can render a system unbootable if used incorrectly. Care must be taken to specify the correct INSTALL_DEVICE or EFI parameters. Modern systems often require careful handling of UEFI variables and boot order, which grub-install manages, but misconfiguration can lead to boot failures. Using update-grub (a Debian/Ubuntu specific wrapper for grub-mkconfig) is generally safer for updating configuration after kernel changes.

GRUB CONFIGURATION FILE (GRUB.CFG)

The primary configuration file for GRUB 2 is /boot/grub/grub.cfg. This file is typically not meant to be edited manually by users. Instead, it is generated by the grub-mkconfig utility (or update-grub on Debian/Ubuntu-based systems) based on templates in /etc/grub.d/ and settings in /etc/default/grub. Manual edits can be overwritten and may prevent the system from booting.

INTERACTIVE GRUB SHELL

When a system fails to boot properly, or during installation, users might encounter the interactive GRUB shell (e.g., grub> or grub rescue>). This command-line environment allows for manual booting, inspecting devices, loading modules, and troubleshooting boot issues using internal commands like ls, set, insmod, linux, initrd, and boot. It's a critical tool for recovery.

HISTORY

GRUB's development began in 1999 as part of the GNU Project. The original GRUB (now referred to as GRUB Legacy) served as the primary bootloader for many Linux distributions. In 2002, GRUB 2 (or GRUB, as it's commonly known today) began development to rewrite and improve upon the legacy version, introducing modularity, better internationalization, and support for a wider range of file systems and firmware interfaces (like UEFI). GRUB 2 became the default bootloader for major distributions around 2010-2012 (e.g., Ubuntu 9.10, Fedora 15, Debian 6.0), largely replacing GRUB Legacy. Its continuous development focuses on supporting new hardware, security features, and ease of configuration, solidifying its role as the de facto standard bootloader for Linux and other UNIX-like systems.

SEE ALSO

grub-mkconfig(8), grub-install(8), grub-probe(8), update-grub(8), os-prober(8)

Copied to clipboard