GRUB
GRUB (GRand Unified Bootloader) is a widely used bootloader that allows users to boot multiple operating systems on a computer. It provides a flexible and powerful way to control the boot process, making it a crucial component in many Linux distributions. Here’s a detailed explanation of GRUB, its configuration, and usage:
Key Features of GRUB
Multiboot Support: GRUB can boot various operating systems, including different versions of Linux, Windows, and other Unix-like systems.
Extensible and Modular: GRUB’s modular design allows for extensions and customizations, making it versatile.
Command-Line Interface: GRUB provides a command-line interface for advanced troubleshooting and configuration.
Graphical Menu Interface: GRUB can display a graphical menu to select from available boot entries.
GRUB Configuration Files
grub.cfg
The primary configuration file for GRUB is grub.cfg
, usually located in /boot/grub
or /boot/efi/EFI/<distro>
on UEFI systems.
This file is auto-generated and should not be edited directly. Instead, make changes to the source files that generate grub.cfg
and regenerate it.
Source Configuration Files
/etc/default/grub: Contains main configuration settings for GRUB.
/etc/grub.d/: Contains scripts that generate
grub.cfg
.
Configuring GRUB
/etc/default/grub
This file allows you to set various options for GRUB. Here are some common settings:
GRUB_DEFAULT: Sets the default menu entry (by index or name).
GRUB_TIMEOUT: Sets the timeout before the default entry is booted.
GRUB_CMDLINE_LINUX_DEFAULT: Adds kernel parameters for the default boot.
GRUB_CMDLINE_LINUX: Adds kernel parameters for all boot entries.
/etc/grub.d/
This directory contains scripts used to create grub.cfg
. Common scripts include:
00_header: Sets up the initial configuration.
10_linux: Adds entries for Linux kernels.
30_os-prober: Adds entries for other operating systems.
Updating GRUB Configuration
After modifying the source configuration files, update grub.cfg
by running:
This command regenerates grub.cfg
based on the scripts in /etc/grub.d/
and settings in /etc/default/grub
.
GRUB Commands
Booting from the Command Line
In case of boot issues, GRUB’s command-line interface can be used to manually boot an operating system.
Access GRUB Command Line: Press
c
at the GRUB menu.Load the Kernel:
Load the Initial RAM Disk:
Boot:
Adding a Boot Entry
You can add a custom boot entry to /etc/grub.d/40_custom
:
Then update GRUB:
Troubleshooting GRUB
Recovering GRUB
If GRUB is broken (e.g., after installing a new OS), you can recover it using a live CD/USB:
Boot from Live CD/USB.
Mount the Root Filesystem:
Mount Other Necessary Filesystems:
Chroot into the Mounted Filesystem:
Reinstall GRUB:
Fixing Boot Entries
If an OS is not appearing in the GRUB menu, run:
Conclusion
GRUB is a powerful and flexible bootloader that provides a robust way to manage the boot process for multiple operating systems. Understanding its configuration files, commands, and troubleshooting techniques is essential for Linux system administration and ensuring smooth system boots.
Last updated