How to use the command 'grub-install' (with examples)

How to use the command 'grub-install' (with examples)

This article provides examples of different use cases for the ‘grub-install’ command, which is used to install GRUB (GNU Grand Unified Bootloader) to a device.

GRUB is a widely used bootloader that allows users to select and boot an operating system or kernel on a computer. The ‘grub-install’ command is part of the GRUB package and is used to install GRUB to a specific device, enabling the computer to boot up properly.

Use case 1: Install GRUB on a BIOS system

Code:

grub-install --target=i386-pc path/to/device

Motivation: This use case is relevant for users who have a computer with a BIOS (Basic Input/Output System) instead of UEFI (Unified Extensible Firmware Interface).

Explanation:

  • --target=i386-pc specifies the target platform for the installation as a BIOS system.
  • path/to/device represents the path to the specific device where GRUB should be installed. This could be something like “/dev/sda” for the primary hard drive.

Example output:

Installation finished. No error reported.

Use case 2: Install GRUB on a UEFI system

Code:

grub-install --target=x86_64-efi --efi-directory=path/to/efi_directory --bootloader-id=GRUB

Motivation: This use case is applicable when installing GRUB on a computer with UEFI firmware, which is becoming increasingly common in modern systems.

Explanation:

  • --target=x86_64-efi sets the installation target as a UEFI system.
  • --efi-directory=path/to/efi_directory specifies the directory where the UEFI firmware stores boot loaders and related files, typically located at “/boot/efi”.
  • --bootloader-id=GRUB sets the unique identifier for the bootloader, which helps the system locate and load it during the boot process.

Example output:

EFI variables are not supported on this system.
EFI variables are not supported on this system.
Installation finished. No error reported.

Use case 3: Install GRUB with pre-loaded modules

Code:

grub-install --target=x86_64-efi --efi-directory=path/to/efi_directory --modules="part_gpt part_msdos"

Motivation: This use case is useful when specific GRUB modules need to be pre-loaded during installation. Loading specific modules can provide additional functionality based on the system’s requirements.

Explanation:

  • --target=x86_64-efi: Specifies the target as a UEFI system.
  • --efi-directory=path/to/efi_directory: Indicates the directory where the UEFI firmware stores boot loaders and related files.
  • --modules="part_gpt part_msdos": Lists the specific modules to be included during the installation. In this case, ‘part_gpt’ and ‘part_msdos’ modules are being loaded.

Example output:

EFI variables are not supported on this system.
EFI variables are not supported on this system.
Installation finished. No error reported.

Conclusion:

The ‘grub-install’ command is a versatile tool for installing GRUB to a device, allowing users to set up proper boot configurations on their systems. The command can be used to install GRUB on both BIOS and UEFI systems, and additional modules can be pre-loaded to enhance functionality according to specific requirements.

Related Posts

How to use the command 'gitk' (with examples)

How to use the command 'gitk' (with examples)

Gitk is a graphical Git repository browser that allows users to visualize and browse through the commits and changes in a Git repository.

Read More
How to use the command bpftrace (with examples)

How to use the command bpftrace (with examples)

bpftrace is a high-level tracing language for Linux eBPF (Extended Berkeley Packet Filter).

Read More
How to use the command 'llc' (with examples)

How to use the command 'llc' (with examples)

The ’llc’ command is a part of the LLVM compiler infrastructure and is used to compile LLVM Intermediate Representation (IR) or bitcode to target-specific assembly language.

Read More