LinuxCommandLibrary

grub-install

Install GRUB bootloader

TLDR

Install GRUB on a BIOS system

$ grub-install --target [i386-pc] [path/to/device]
copy

Install GRUB on an UEFI system
$ grub-install --target [x86_64-efi] --efi-directory [path/to/efi_directory] --bootloader-id [GRUB]
copy

Install GRUB pre-loading specific modules
$ grub-install --target [x86_64-efi] --efi-directory [path/to/efi_directory] --modules "[part_gpt part_msdos]"
copy

SYNOPSIS

grub-install [OPTION...] install_device

PARAMETERS

--target=platform
    Specify the target platform (e.g., i386-pc, x86_64-efi).

--boot-directory=dir
    Directory containing GRUB images. Defaults to /boot/grub or /boot/efi/EFI/distro/.

--recheck
    Probe all devices again before installation.

--modules=module_list
    Preload specified GRUB modules.

--no-floppy
    Do not probe for floppy drives.

--force
    Install even if problems are detected.

--removable
    Installation for removable media.

--efi-directory=dir
    The EFI System Partition (ESP) mount point (for UEFI systems).

--bootloader-id=ID
    Bootloader ID string for UEFI.

--version
    Show the version number and exit.

--help
    Show help text and exit.

DESCRIPTION

The grub-install command is used to install the GRand Unified Bootloader (GRUB) onto a specified target device. GRUB is responsible for loading the operating system kernel at boot time. grub-install sets up the necessary files and boot sectors so that the system can boot correctly.
The command analyzes the system's configuration, including the available operating systems and file systems, to determine the appropriate GRUB modules and configuration file. It copies these files to the boot partition and updates the Master Boot Record (MBR) or EFI System Partition (ESP) with the necessary boot code. Incorrect usage can render a system unbootable, so using the correct parameters for your hardware and boot configuration is essential. It supports different architectures and installation methods, adapting to varying BIOS and UEFI environments. Its primary role is to bridge the gap between the hardware and the operating system, allowing the user to choose which OS to boot at startup. It also handles potential bootloader issues such as corruption or misconfiguration.

CAVEATS

Incorrect use of grub-install can render a system unbootable.
Be extremely careful when specifying the target device, particularly in multi-disk setups. Ensure that the specified target device is the correct one that the system boots from.

UEFI CONSIDERATIONS

When installing GRUB on a UEFI system, the --target and --efi-directory options are crucial. The --efi-directory must point to the mounted EFI System Partition (ESP). Ensure the ESP is properly mounted before running grub-install.

MBR VS. GPT

grub-install behaves differently depending on whether the disk uses MBR (Master Boot Record) or GPT (GUID Partition Table). On MBR disks, it writes the GRUB boot code to the MBR. On GPT disks, it typically installs the GRUB bootloader to a dedicated BIOS Boot Partition or to the ESP.

HISTORY

grub-install is a part of the GNU GRUB project, which has been under continuous development since the late 1990s.
It replaced LILO as the primary bootloader in many Linux distributions. Over time, it has been adapted to support new hardware architectures, file systems, and boot methods, including UEFI. The command has evolved to handle complexities introduced by modern storage devices and boot configurations. It is widely deployed and considered essential for booting most Linux systems. The transition from GRUB Legacy (GRUB 1) to GRUB 2 involved substantial changes to the command and its underlying mechanisms.

SEE ALSO

grub-mkconfig(8), grub-update(8)

Copied to clipboard