GRUB stands for Grand Unified Bootloader, a popular bootloader program used in many Linux distributions. This is the first program that runs when the computer starts enabling the selection of the Operating System among all other installed OSs. The GRUB program loads Kernel at the system boot time and lets the user pass arguments to the Kernel. In this article, you will know what is GRUB in Linux, its features, interfaces, and how it works in the boot process.
What is GRUB in Linux?
GRUB is the default boot loader for many Linux Distributions. It provides a flexible and configurable way to boot a system. When a computer starts up, the BIOS (Basic Input-Output System) on the motherboard initializes the hardware and then looks for a bootable program. And, this bootloader program is responsible for loading the operating system from the selected device into memory and transferring control to it. GRUB also allows the user to choose which operating system to boot from a menu.
Features of GRUB
GRUB is a popular bootloader used on Linux and other Unix-like Operating Systems. It is known for its flexibility and wide range of features, such as,
- Multiboot→GRUB can bot multiple OSs, including Linux, Windows, and BSD from a single bootloader menu.
- Boot-time configuration→It can be configured at boot time, allowing users to change the boot options, such as default OS or Kernel parameters.
- Graphical Boot menu→ It supports a graphical boot menu with customizable themes and fonts.
- Advanced scripting→ It uses a built-in scripting language that allows advanced boot-time operations, such as detecting hardware.
- Filesystem support→GRUB can boot from a variety of filesystems, including Ext2, Ext3, Ext4, XFS, NTFS, FAT,
- Encryption support→It supports encrypted filesystems. That way users can encrypt their entire boot process.
- Network Booting→ GRUB can boot from a network server using Preboot Execution Environment (PXE) protocol allowing for remote booting.
- Dynamic module loading→ It can load modules dynamically, allowing for additional features and drivers to be loaded as needed.
GRUB Boot Process in Linux
The main function of GRUB is to load the Operating System Kernel and necessary system files into memory so that the OS can be started. Here is an overview of the GRUB boot process or in a simple context, how it works in the boot process in steps.
- At first, when a user power on a computer, the firmware (BIOS or UEFI) executes its initialization code and performs some basic hardware checks.
- After completing initialization the firmware looks for a bootloader in a specific location of the disk. If the system has GRUB installed, the firmware loads it in memory.
- Then the GRUB presents a menu of available OSs or kernels list to choose from. Users can select any of them.
- GRUB reads its configuration file, which is typically located at /boot/grub/grub.conf and contains the necessary settings for the boot process.
- After the user selects the desired OS or kernel, the bootloader loads the Kernel and an optional initial ramdisk (inird) into memory. The inird contains any necessary device drivers or modules required to mount the root file system.
- Then the kernel starts executing and performs its initialization, such as hardware detection, device initialization, and module loading. This initialization process is the first user-space process that is responsible for starting all other processes and initializing the system.
- After the initialization process completes, the user login prompt pops up and the user can log in to the system.
Boot Loader vs Boot Manager
Even though GRUB works both as A bootloader and boot manager you may want to learn distinctively about them. Both bootloader and boot manager are components of a computer’s boot process, but they serve slightly different functions. A bootloader is a program that is loaded at startup to load and execute OS, whereas, a boot manager is a program that allows the user to choose which OS to boot there are multiple installed OSs on the computer. And, GRUB is a hybrid tool that functions as both a bootloader and a boot manager. See the below chart to see what GRUB does when it acts as a bootloader and as a boot manager from the differences between them,
|Loads and executes the OS.
|Allows the user to choose which OS to boot.
|Typically located in the first sector of the boot device.
|Usually installed in the boot partition of the hard drive.
|Loaded by the computer’s firmware at startup.
|Loaded after the boot loader.
|It does not require any user interface.
|Provides a menu for the user to select the OS they want to use.
|GRUB, Windows boot manager.
|GRUB, Clover, system-boot.
GRUB has several interfaces that users can use to interact with the bootloader and configure its settings. Some of them are,
- Command-line interface→ GRUB has a built-in CLI that you can access by pressing the “c” key at the bootloader menu.
- Graphical interface→ It also supports a graphical interface that displays a menu with available OSs and boot options. Users can customize the interface with themes and icons too.
- Menu Interface→ GRUB comes with a default menu interface. It contains a list of OSs or kernels arranged in order by name. Users can select from the menu using the arrow key.
- Boot-time prompt→ User can configure GRUB to display a boot-time prompt that allows him to choose which OS to boot or to enter boot options.
- Rescue mode→ It includes a rescue mode that users can use to recover from boot errors or to fix problems with the bootloader or operating system. The rescue mode provides a minimal command-line environment with basic tools for repairing the system.
Models of Grub in Linux
GRUB has gone through several major revisions, each with different models. Following are some main versions that took place in the journey,
A. GRUB Legacy:
This is the original version and is no longer maintained. Even though some old Linux distributions still use it.
B. GRUB 2:
This is the current version and is actively maintained. It provides many new features and improvements over GRUB Legacy, including support for modern hardware and more flexible configuration options.
C. Embedded GRUB:
This version is designed to be used in embedded systems, such as routers or set-top boxes. It is a stripped-down version of GRUB 2, with fewer features and a smaller code.
The GRUB configuration file is normally situated at /boot/grub/grub.conf in most Linux distributions. But it is not recommended to edit this file directly as it gets overwritten each time GRUB is updated. Instead, the configuration should be modified by editing the files located in the /etc/grub/d/ directory. These files are responsible for generating the grub.cfg file based on the configuration options specified within them. Each of the files in the directory has a specific purpose and is numbered to ensure that the final ‘grub.cfg’ file is assembled in the correct order.
To modify the GRUB configuration, you can edit the file in the /etc/grub.d/ directory using a text editor. Once you have made your changes, you can run the “sudo update-grub” command to regenerate the ‘grub.cfg’ file. This will update the GRUB menu with your new settings.
After the BIOS, GRUB is the first software that runs when you start a Linux computer. It is a crucial component of the boot process. Understanding how GRUB works and how to configure it can help users troubleshoot boot-related issues. In this article, I discussed the basics of GRUB in the introductory phase. This is the primary knowledge you need to further learn how to configure GRUB for troubleshooting, in addition to recovering various boot-related issues. Hope this essay helps you.