The bootloader is an essential operating system component that assists with hardware initialization and loading of the software components necessary for a successful boot process. If a computer has multiple operating systems, bootloaders provide a user interface that enables you to select which OS to load.
This article introduces the GRUB bootloader and explains its function and purpose within a Linux system.
What Is GRUB?
GRUB (also known as GNU GRUB or GNU Grand Unified Bootloader) is a bootloader and boot manager for Linux and other Unix-based OSes. GRUB starts after BIOS finishes the necessary hardware tests and loads it from the Master Boot Record (MBR). Once loaded, GRUB takes control of the system and loads the Linux kernel.
There are two versions of GRUB currently available for Linux:
- GRUB Legacy (GRUB 1). This deprecated version of GRUB is still found on some older Linux distributions.
- GRUB 2. This GRUB version supports new PC architectures (such as ARM) and filesystems (such as ReiserFS), RAID environments, and LVM. Most of the current distributions use GRUB 2. For example, below is the GRUB menu found in Linux Mint:
Bootloader vs. Boot Manager
GRUB functions as both a bootloader and a boot manager. These two components perform distinct functions during system startup.
- The bootloader loads the system kernel from a storage device (hard disk drive or SDD) to RAM. Bootloaders also assist with hardware initialization tasks, such as setting up memory and configuring the CPU.
- The boot manager presents the user with an interface where they manage boot configuration and choose which system to load. The interface can be a simple default GRUB menu or be customized for a particular distribution, e.g., Kali Linux:
What Does GRUB Do?
Once BIOS loads GRUB into the memory, GRUB presents the user with a menu with boot options. These options include the operating systems installed on the system and special boot options, such as the safe mode.
After the user selects an option or the time allotted for the choice expires, GRUB loads the corresponding kernel. To complete this process successfully, GRUB considers the following parameters:
BOOT_IMAGE. This parameter specifies the location of the Linux Kernel.
initrd(initial ramdisk). A scheme that shows how to load a temporary root filesystem into RAM.
root. The location of the root filesystem.
quiet. A configuration option to hide system-related output during the boot-up process.
ro. This parameter specifies that the filesystem should be mounted as read-only to enable filesystem consistency check programs (fsck).
splash. The splash screen to display during the OS booting.
GRUB Boot Process
The GRUB boot process consists of two or three stages:
- Stage 1. The initial GRUB stage starts right after BIOS loads GRUB from the MBR. GRUB uses the small space allocated for the initialization code in the MBR to start the next, more complex stage.
- Stage 1.5. This optional stage enables dynamic reading of the Stage 2 file. GRUB supports multiple filesystems and installs the one corresponding to the filesystem on which the Stage 2 file resides. If Stage 1.5 is missing during GRUB installation, Stage 2 loads statically.
- Stage 2. The final stage of the GRUB boot process is the longest and most complex. This stage contains all the steps essential for the system startup, including:
- Displaying the boot menu.
- Loading the OS kernel.
- Initializing the kernel.
- Initializing the user-space.
GRUB is a versatile and robust bootloader designed to support the requirements of modern operating systems. Below is the list of the essential GRUB features:
- Modular architecture. GRUB’s modular design sidesteps the limitations of BIOS and allows it to offer more features.
- Flexible configuration. By editing GRUB’s configuration file, users can customize various aspects of their system, such as default boot entry, kernel parameters, and timeout durations.
- Multi-boot support. GRUB provides a boot menu and makes it easy for multi-OS system users to choose which operating system to run.
- Dynamic detection. GRUB dynamically detects installed OSs and generates boot entries.
- Chainloading. GRUB can integrate with other bootloaders, such as Windows Boot Manager and NTLDR.
- Filesystems support. Support for various filesystems (such as ext2, ext3, ext4, Btrfs, HFS+, NTFS, FAT, and ReiserFS) makes GRUB a safe choice for running any UNIX-based OS.
- Scripting language. Users who need to create custom boot configurations and automation can use GRUB’s scripting language.
- Password protection. GRUB increases the system’s security by offering password protection for the bootloader menu.
- Rescue mode. The rescue mode helps users troubleshoot and fix boot-related problems.
- Legacy BIOS and UEFI support. GRUB works with both traditional BIOS and modern UEFI firmware.
- Network Boot. GRUB supports PXE boot, enabling computers in the network to be booted by the server.
How to Access and Edit GRUB?
Change GRUB configuration and customize its interface by editing its configuration file. GRUB configuration is performed via a terminal application on your system and requires administrative privileges.
Editing GRUB Configuration File
Note: Misconfiguration of GRUB can prevent your system from booting. Ensure you have fresh system backups before editing the configuration file.
To start configuring GRUB:
sudo nano /etc/default/grub
The file contains parameters that control how GRUB behaves. Here are a few commonly edited settings:
GRUB_DEFAULT. Sets a numeric index or menu entry title as the default boot entry.
GRUB_TIMEOUT. Defines the number of seconds GRUB shows the boot menu before booting the default option.
GRUB_HIDDEN_TIMEOUT. Hides or shows the GRUB menu.
GRUB_CMDLINE_LINUX. Defines kernel command-line parameters.
GRUB_DISABLE_OS_PROBER. Disables dynamic OS detection.
2. When you finish making changes to the file, save the file and exit the editor. Then, use the following command to apply changes in the terminal:
This command scans for changes to
/etc/default/grub and applies them to
grub.cfg, the file GRUB uses during the booting process.
3. Restart the computer for the changes to take effect.
Editing GRUB Interface
The configuration file can also change GRUB’s appearance on your system. Follow the steps below to customize GRUB:
1. Open the configuration file in a text editor:
sudo nano /etc/default/grub
2. Look for the parameters that define the look of GRUB’s boot manager:
GRUB_BACKGROUND. This parameter allows you to set a custom background image. Use the following syntax:
GRUB_THEME: If your distribution supports GRUB themes, set the path to the theme file here.
Save the file and exit.
4. Update GRUB:
The customizations show on the next restart.
GRUB Customizer is a GUI tool for changing GRUB’s look and feel without manually editing configuration files. Install it via the terminal by following the steps below:
1. Add the GRUB Customizer repository:
sudo add-apt-repository ppa:danielrichter2007/grub-customizer
Press Enter to confirm the repository addition and wait for the process to finish.
2. Update the repository information:
sudo apt update
3. Install GRUB Customizer:
sudo apt install grub-customizer
Y and press Enter to start the installation.
4. Launch the program by typing:
GRUB Customizer’s GUI window appears.
Here are a few valuable features of the GRUB customizer:
- Simple GUI interface for rearranging boot entries in the boot menu and setting the default boot entry.
- Personalization options for changing the GRUB menu background image and general appearance.
- Options to adjust the timeout value.
- A graphical way to modify kernel parameters and GRUB’s environment variables.
- Options to install GRUB to a specific partition or device.
After reading this article, you should know more about GRUB, its features, and how to configure it to suit your needs. The article also introduced the GRUB Customizer, a GUI tool to edit GRUB configuration.
Next, learn How to Use Grub Rescue to Fix Linux Boot Failure.
Đăng ký liền tay Nhận Ngay Bài Mới
Cám ơn bạn đã đăng ký !
Lỗi đăng ký !