Understanding the GRUB 2 bootloader

UEFI Instead of GRUB 2?

You may be wondering if you could skip GRUB 2 and use UEFI to boot different operating systems like Windows, Linux, macOS, and others. The answer is no. UEFI and GRUB 2 have different purposes. UEFI allows you to choose the medium from which you boot and then turns things over to the bootloader, which can be GRUB 2 or another option.

The confusion arises because UEFI has its own boot menu, which you launch by pressing F7, F8, or some other key at boot time (the key used depends on your computer, and you will find this information in your operating system's manual). UEFI also has a shell, just like GRUB 2. However, the UEFI shell is not always included in your operating system's standard installation.

From the UEFI menu, you can choose which operating system to boot. Once you choose, UEFI will call the bootloader corresponding to the operating system you wish to boot. You can configure UEFI with the command bootmgr from the Unix shell, but not all operating systems come with the bootmgr utility installed [3]. You can download the UEFI shell from GitHub [4] or from your operating system's packages (e.g., Debian [5]).

Installing GRUB 2 on Linux

Most Linux distributions will install GRUB 2 for you as part of the normal installation process. However, there are a few situations that require manually installing GRUB 2.

Installing several operating systems on one hardware can cause the standard installation procedure to get confused. You could use virtualization as an alternative to multi-boot, but virtualization solutions do not support all hardware requirements (e.g., some GPUs).

Some situations require a fresh installation of GRUB 2, most commonly when the current GRUB 2 installation has been destroyed. A less common situation occurs after installing a Linux distribution that uses a different bootloader that overwrites the actual configuration, or if you intentionally installed another bootloader and simply want to go back.

To get started with a manual installation, you need to install GRUB 2, if not yet present on your distribution. You'll find instructions for this online, including at FossLinux [6]. Figure 5 shows a typical GRUB 2 installation on the UEFI platform.

Figure 5: Installing GRUB 2 on the UEFI platform.

First, you need to update the operating system. Once it is updated, you then install the GRUB 2 UEFI software (grub-efi). Next, you need to mount the partition, which is used for UEFI. This partition must be formatted to FAT32. Once mounted, you install GRUB with the command grub-install (Figure 5). That's it.

Installing GRUB 2 for legacy BIOS is easier. Like with UEFI, you first update your operating system before installing the GRUB 2 installer (grub-pc in this instance). Once downloaded, you again launch the command grub-install, which will install GRUB 2 in the disk's MBR. The installer will know where to find it.

Configuring GRUB 2

Once installed, GRUB 2 needs to be configured. Again, in most cases, the GRUB 2 installation procedure makes the "best guess" to ensure that the current operating system's boot process goes well. If you want something different from the standard installation, you need to do some additional configuration steps.

GRUB 2 gets its parameters from a file called grub.cfg. You should never modify this file, because it is generated automatically, and any changes to this file will be overwritten at the next kernel update. The grub.cfg file is generated from the configuration file grub.conf, which is located in /etc/default. The second source of input to grub.cfg is the contents of /etc/config/grub. The files in this directory get loaded in the same sequence used by ls.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • In-Depth Security

    More than just a boot manager, GRUB 2 can help you add another line of protection to your security defenses.

  • Grub Customizer

    Is the simple black and white GRUB menu causing confusion and obscuring important choices? Why not customize with GRUB themes and the Grub Customizer?

  • Exercise Place

    The GRUB 2 boot manager might seem intimidating at first glance. All the more reason to spin up a virtual playground so you can practice.

  • GRUB GUIs

    A graphical tool might be your best option for configuring or adapting the GRUB2 boot loader.

  • Configuring Dual Boot

    When two systems share a single computer, a boot manager handles the prompts that determine which system to boot. We’ll show you several multiple boot scenarios and describe how to set up your system for dual booting Linux with Windows.

comments powered by Disqus
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters

Support Our Work

Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.

Learn More

News