GRUB doesn’t just load your OS; it’s the gatekeeper of your entire system, and understanding its configuration is your key to unlocking boot-time control and disaster recovery.

Imagine this: you’ve just installed a new Linux distribution, or perhaps you’re dual-booting with Windows. When you power on your machine, before any operating system even starts to wake up, a small program called the bootloader takes over. In the Linux world, the most common bootloader is GRUB (GRand Unified Bootloader). Its primary job is to present you with a menu, allowing you to choose which operating system to boot, and then load the selected OS’s kernel into memory. But GRUB is far more than just a menu; it’s a powerful, extensible system that can be configured to manage complex boot scenarios, troubleshoot boot failures, and even recover a broken system.

Let’s see GRUB in action. On a typical Linux system, when you boot up, you’ll see a GRUB menu like this:

GNU GRUB version 2.06

  Ubuntu
  Advanced options for Ubuntu
  Windows Boot Manager (on /dev/sda1)
  System setup

If you select "Ubuntu," GRUB loads the Linux kernel and initial RAM disk, then passes control to the kernel to start the boot process of your operating system. If you were to select "Windows Boot Manager," GRUB would hand off control to the Windows bootloader, allowing you to boot into Windows.

The core of GRUB’s configuration lies in its main configuration file, typically located at /boot/grub/grub.cfg. However, you should never edit this file directly. Instead, GRUB uses a set of scripts and configuration files that are processed to generate grub.cfg. The primary file you’ll interact with for manual configuration is /etc/default/grub.

Here’s a breakdown of what you can control via /etc/default/grub:

  • GRUB_DEFAULT: This sets the default entry that GRUB will boot if no selection is made within the timeout period. It can be a number (0 for the first entry, 1 for the second, etc.), or the exact name of a menu entry (e.g., GRUB_DEFAULT="Ubuntu").
    # Example: Boot Ubuntu by default
    GRUB_DEFAULT=0
    
  • GRUB_TIMEOUT: The number of seconds GRUB will wait for user input before booting the default entry. Setting it to 0 means it boots immediately without showing the menu. A value of -1 means it waits indefinitely.
    # Example: Wait 10 seconds before booting the default
    GRUB_TIMEOUT=10
    
  • GRUB_CMDLINE_LINUX_DEFAULT: This option allows you to pass kernel parameters to the Linux kernel at boot time. These parameters can be used for debugging, enabling specific hardware, or setting system behavior.
    # Example: Add 'quiet splash' for a cleaner boot and 'intel_pstate=disable' for a specific CPU issue
    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash intel_pstate=disable"
    
  • GRUB_DISABLE_OS_PROBER: Set to true to disable GRUB’s ability to detect other operating systems on your system. This can be useful for security or if you only want to boot Linux.
    # Example: Prevent GRUB from scanning for other OSes
    GRUB_DISABLE_OS_PROBER=true
    

After making changes to /etc/default/grub, you must update GRUB’s configuration by running:

sudo update-grub

This command reads /etc/default/grub and other relevant files, generates the actual grub.cfg, and installs it.

GRUB’s rescue capabilities are where its true power shines. If your system fails to boot, you can often recover it by using the GRUB command line. To access this, you typically need to interrupt the boot process by pressing the c key when the GRUB menu appears.

Once at the GRUB command prompt, you can manually boot your system. The key commands are:

  • ls: Lists devices and partitions. For example, ls (hd0,gpt1)/ will list the contents of the first partition on the first hard drive.
  • set root=(<device>,<partition>): Sets the root device and partition for GRUB. For example, set root=(hd0,gpt2) tells GRUB to look for files on the second partition of the first hard drive.
  • linux /boot/vmlinuz-<version> root=/dev/sdXN: Loads the Linux kernel. You’ll need to specify the correct kernel image path and the root device for your system (e.g., root=/dev/sda2).
  • initrd /boot/initrd.img-<version>: Loads the initial RAM disk.
  • boot: Starts the boot process.

For instance, to boot a system where your root partition is /dev/sda2 and your kernel is vmlinuz-5.15.0-56-generic:

grub rescue> ls
(hd0) (hd0,gpt2) (hd0,gpt1)
grub rescue> set root=(hd0,gpt2)
grub rescue> linux /boot/vmlinuz-5.15.0-56-generic root=/dev/sda2
grub rescue> initrd /boot/initrd.img-5.15.0-56-generic
grub rescue> boot

This interactive mode is invaluable for diagnosing boot issues, such as when update-grub fails or when partitions are renumbered.

The one thing most people don’t realize is that GRUB can be installed on multiple devices. When you install GRUB, you’re not just installing a file; you’re installing boot code into the Master Boot Record (MBR) or the EFI System Partition (ESP) of a specific disk. If you have multiple disks with operating systems, or if you’re moving a disk to a new machine, you might need to reinstall GRUB to the correct disk’s boot sector using grub-install /dev/sdX (where /dev/sdX is the target disk, not a partition).

Beyond basic boot configuration, GRUB supports features like UEFI booting, LVM, and RAID, making it a versatile tool for modern systems.

The next step after mastering GRUB configuration is understanding how to manage kernels and their versions.

Want structured learning?

Take the full Linux & Systems Programming course →