How to check if a specific bootloader is used in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check which bootloader is being used on a Linux system, specifically focusing on GRUB. You will explore the key configuration files located in the /boot/grub directory to understand the components of your GRUB installation.

You will then examine the /etc/default/grub file to verify the main configuration settings that control GRUB's behavior. Finally, you will inspect the bootloader logs using the dmesg command to confirm which bootloader was loaded during system startup.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/TextProcessingGroup(["Text Processing"]) linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/TextProcessingGroup -.-> linux/grep("Pattern Searching") subgraph Lab Skills linux/ls -.-> lab-558753{{"How to check if a specific bootloader is used in Linux"}} linux/cat -.-> lab-558753{{"How to check if a specific bootloader is used in Linux"}} linux/grep -.-> lab-558753{{"How to check if a specific bootloader is used in Linux"}} end

Check GRUB with ls /boot/grub

In this step, we will explore the GRUB bootloader configuration files. GRUB (GRand Unified Bootloader) is the default bootloader for most Linux distributions, including Ubuntu. It's the first software that runs when you start your computer, responsible for loading the operating system kernel into memory.

The main GRUB configuration files are typically located in the /boot/grub directory. Let's list the contents of this directory to see what's inside.

Open your terminal if it's not already open. Remember, you can find the Xfce Terminal icon on the left side of your desktop.

Type the following command and press Enter:

ls /boot/grub

The ls command is used to list files and directories. When you provide a path like /boot/grub, it lists the contents of that specific directory.

You should see a list of files and directories, which might look something like this (the exact output may vary slightly depending on the system):

fonts  grub.cfg  grubenv  i386-pc  locale  unicode.pf2  x86_64-efi

This output shows the various components of your GRUB installation. The most important file here is grub.cfg, which contains the actual boot menu configuration. We'll look at that file in the next step.

Understanding the contents of /boot/grub is the first step in learning how your Linux system boots up.

Click Continue to proceed to the next step.

Verify GRUB config with cat /etc/default/grub

In the previous step, we listed the contents of the /boot/grub directory and saw the grub.cfg file. While grub.cfg is the active configuration file, it's usually generated automatically from settings defined in /etc/default/grub and scripts in /etc/grub.d/.

The /etc/default/grub file contains the main configuration options that control how GRUB behaves, such as the default operating system to boot, the timeout before booting, and kernel parameters.

Let's view the contents of the /etc/default/grub file using the cat command. The cat command is used to display the content of files.

Type the following command in your terminal and press Enter:

cat /etc/default/grub

You will see the contents of the GRUB default configuration file. It will look something like this:

## If you change this file, run 'update-grub' afterwards to update
## /boot/grub/grub.cfg.

GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""

## Uncomment to enable booting from a full graphics screen using grub-gfxpayload
## and grub-theme-ubuntu-mate ...
#GRUB_GFXPAYLOAD_LINUX=keep

## Uncomment to disable graphical terminal (grub-pc only)
#GRUB_TERMINAL=console

## The resolution used on graphical terminal
## Note that you can only use resolutions specified in your gfxpayload.
## See the Graphics chapter in the Grub manual for more details.
#GRUB_GFXMODE=640x480

## Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to the Linux kernel
#GRUB_DISABLE_LINUX_UUID=true

## Uncomment to disable generation of recovery mode menu entries
#GRUB_DISABLE_RECOVERY="true"

## Uncomment to get a beep at boot start
#GRUB_INIT_TUNE="480 440 1"

This file contains various settings, each explained by comments starting with #. For example:

  • GRUB_DEFAULT: Specifies the default menu entry to boot. 0 usually means the first entry.
  • GRUB_TIMEOUT: Sets the time in seconds before the default entry is automatically booted.
  • GRUB_CMDLINE_LINUX_DEFAULT: Contains kernel parameters passed to the default boot entry.

Understanding this file is crucial if you ever need to modify boot options, such as adding kernel parameters for troubleshooting or changing the default operating system.

Click Continue to move on to the next step.

Inspect bootloader logs in dmesg

In the previous steps, we looked at the GRUB configuration files. Now, let's examine the messages generated by the kernel during the boot process. These messages are stored in a buffer and can be viewed using the dmesg command.

dmesg (diagnostic message buffer) is a command that prints the message buffer of the kernel. It contains information about hardware devices, device drivers, and other kernel-related messages that are generated during system startup. This is a valuable tool for troubleshooting boot issues.

Type the following command in your terminal and press Enter:

dmesg

This will output a large amount of text, showing all the kernel messages since the system started. The output can be overwhelming, so it's common to filter it or pipe it to a pager like less to view it screen by screen.

To see messages specifically related to the bootloader or early boot process, you can often look for keywords like "GRUB", "boot", or "kernel command line".

Let's try filtering the output using grep to find lines containing "Command line":

dmesg | grep "Command line"

The | symbol is called a pipe. It takes the output of the command on the left (dmesg) and sends it as input to the command on the right (grep). grep is a powerful tool for searching text patterns. In this case, we are searching for lines that contain the phrase "Command line".

You should see output similar to this, showing the kernel command line parameters passed by the bootloader:

[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-... root=UUID=... ro quiet splash

This line shows the kernel image being booted (/boot/vmlinuz-...) and the kernel parameters (root=UUID=... ro quiet splash). These parameters are often set in the /etc/default/grub file we saw in the previous step.

Exploring dmesg is essential for diagnosing problems that occur during the boot process, as it provides detailed information about what the kernel is doing from the very beginning.

Click Continue to complete this lab.

Summary

In this lab, we learned how to check if GRUB is the bootloader used in a Linux system. We started by listing the contents of the /boot/grub directory using the ls command to identify the presence of GRUB configuration files, particularly grub.cfg. This step confirmed the existence of a GRUB installation.

Following that, we examined the /etc/default/grub file using the cat command. This file contains the primary configuration settings for GRUB, such as default boot options and timeout values. By inspecting this file, we further verified that GRUB is configured as the bootloader and gained insight into its behavior.