grub-install
system managementLinux
The grub-install command is one of the most frequently used commands in Linux/Unix-like operating systems. grub-install Install GRUB bootloader on a device
Quick Reference
Command Name:
grub-install
Category:
system management
Platform:
Linux
Basic Usage:
grub-install [options] [arguments]
Common Use Cases
Syntax
grub-install [options] [--target=target] [device]
Options
Option | Description |
---|---|
--target=TARGET | Install GRUB for TARGET platform [default=i386-pc] |
--boot-directory=DIR | Install GRUB images under the directory DIR/grub instead of the default /boot/grub |
--efi-directory=DIR | Use DIR as the EFI System Partition root |
--bootloader-id=ID | The ID of bootloader for EFI or Macs. The default is 'grub' |
--removable | Install GRUB for removable media (for EFI only) |
--recheck | Delete device map if it already exists |
--force | Install even if problems are detected |
--allow-floppy | Make the drive also bootable as a floppy (default for fdX devices) |
--modules=MODULES | Pre-load specified modules MODULES |
--no-nvram | Don't update the NVRAM (for EFI only) |
--no-bootsector | Don't install bootsector |
--help | Display help information and exit |
--version | Output version information and exit |
Examples
How to Use These Examples
The examples below show common ways to use the grub-install
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
grub-install /dev/sda
Install GRUB to the master boot record (MBR) of the first disk.
grub-install --target=x86_64-efi --efi-directory=/boot/efi
Install GRUB for UEFI systems, with the EFI directory at /boot/efi.
# Advanced Examples Advanced
grub-install --boot-directory=/mnt/boot /dev/sdb
Install GRUB to /dev/sdb, using /mnt/boot as the boot directory.
grub-install --target=i386-pc --recheck /dev/sda
Install GRUB for BIOS systems with probe device map.
grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB
Install GRUB for UEFI systems with a specific bootloader ID.
grub-install --target=x86_64-efi --efi-directory=/boot/efi --removable
Install GRUB for UEFI removable installations.
Try It Yourself
Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.
Understanding Syntax
Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.
Notes
The grub-install command is used to install the GRUB bootloader onto a device, which is a critical component for booting most Linux systems. GRUB (GRand Unified Bootloader) provides a menu to select different operating systems or kernel versions during the boot process.
Key features of grub-install:
1. Multiple Platform Support: grub-install can target different hardware platforms, including traditional BIOS systems (i386-pc), UEFI systems (x86_64-efi), and others, making it versatile across various hardware configurations.
2. Boot Directory Configuration: The command allows specifying a custom boot directory, which is useful when installing GRUB to a different system (e.g., during installation or recovery).
3. UEFI Support: For systems using UEFI firmware, grub-install can properly set up the EFI System Partition (ESP) and register the bootloader with the firmware.
4. Removable Media Installation: The --removable option enables creating bootable USB drives or other removable media with GRUB installed.
5. Device Map Management: With the --recheck option, grub-install can recreate the device map, which helps resolve issues when disk configurations change.
6. Module Loading: The command can be configured to pre-load specific GRUB modules, which extends functionality for specialized boot requirements.
7. NVRAM Management: For UEFI systems, grub-install updates the NVRAM to add GRUB as a boot option, though this can be disabled if needed.
Common use cases include setting up a bootloader during system installation, repairing a broken boot configuration, creating bootable recovery media, and updating the bootloader after system changes. It's an essential tool for system administrators and users who need to manage boot configurations on Linux systems.
Related Commands
These commands are frequently used alongside grub-install
or serve similar purposes:
Use Cases
Learn By Doing
The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the grub-install command works in different scenarios.
$ grub-install