How to check if GRUB settings are applied in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, we will learn how to verify if changes made to the GRUB bootloader configuration in Linux have been successfully applied. We will explore the primary GRUB configuration file located at /etc/default/grub to understand its settings.

Following that, we will examine the generated GRUB menu configuration file at /boot/grub/grub.cfg to see how the settings from the default file are translated. Finally, we will inspect the kernel boot parameters using the dmesg command to confirm that the GRUB settings are reflected in the running system.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/TextProcessingGroup(["Text Processing"]) linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/TextProcessingGroup -.-> linux/grep("Pattern Searching") subgraph Lab Skills linux/cat -.-> lab-558789{{"How to check if GRUB settings are applied in Linux"}} linux/grep -.-> lab-558789{{"How to check if GRUB settings are applied in Linux"}} end

Check GRUB config with cat /etc/default/grub

In this step, we will explore the GRUB configuration file. GRUB (GRand Unified Bootloader) is the boot loader for many Linux distributions, including Ubuntu. It's the first software that runs when you start your computer, and it's responsible for loading the operating system kernel.

The main configuration file for GRUB is located at /etc/default/grub. This file contains settings that determine how GRUB behaves, such as the default operating system to boot, the timeout before booting, and kernel parameters.

Let's view the contents of this file using the cat command. The cat command is used to display the content of files.

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:

cat /etc/default/grub

You will see the content of the /etc/default/grub file printed in your terminal. 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 graphical terminal (grub-gfxpayload is needed)
#GRUB_TERMINAL=gfxterm

## The resolution used on graphical terminal
## settings below may not work on your chipset but may be useful for EFI panel
## sizes
#GRUB_GFXMODE=640x480

## Uncomment to disable graphical terminal on boot problems
#GRUB_TERMINAL_INPUT=console

## Uncomment to disable menu scrolling
#GRUB_MENU_SCROLL_STYLE=menu

## Uncomment to enable hidden menu by default
#GRUB_HIDDEN_TIMEOUT=0
#GRUB_HIDDEN_TIMEOUT_QUIET=true

## Uncomment to enable BadRAM filtering, modify to suit your needs
## This works only with Linux 2.6.25 or later using pci_filter_enable=1
## and needs BadRAM filtering support in the kernel
#GRUB_BADRAM="0x0123456789abcdef,0xghijkllmnopqrstuvwxyz"

## Uncomment to disable graphical boot (use text mode)
#GRUB_DISABLE_GRAPHICS_OVERRIDE=true

## If you want to enable the GRUB boot menu at boot time, uncomment the following line:
#GRUB_ENABLE_CRYPTODISK=y

## The following lines are for the default grub menu entry
#GRUB_INIT_TUNE="480 440 1"

## Uncomment to set a custom theme
#GRUB_THEME=/path/to/grub/theme

## Uncomment to enable os-prober, which detects other operating systems
#GRUB_DISABLE_OS_PROBER=false

This file contains various settings. For example:

  • GRUB_DEFAULT: Specifies the default menu entry to boot. 0 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 that are passed to the kernel when booting the default entry.

Understanding this file is crucial for advanced Linux configuration and troubleshooting boot issues.

Click Continue to proceed to the next step.

In the previous step, we looked at /etc/default/grub, which is the primary configuration file for GRUB. However, this file is not directly used by GRUB during the boot process. Instead, the settings in /etc/default/grub are used to generate the actual GRUB menu configuration file, which is located at /boot/grub/grub.cfg.

The /boot/grub/grub.cfg file is automatically generated by the update-grub command (or grub-mkconfig). It contains the menu entries that you see when the computer starts, allowing you to choose which operating system or kernel to boot.

Important: You should never manually edit the /boot/grub/grub.cfg file. Any changes you make will be overwritten the next time update-grub is run. Always modify /etc/default/grub and then run sudo update-grub to apply your changes.

Let's view the contents of the /boot/grub/grub.cfg file using the cat command.

Type the following command in your terminal and press Enter:

cat /boot/grub/grub.cfg

You will see a much longer and more complex output compared to /etc/default/grub. This file contains the detailed configuration for each boot menu entry, including the kernel path, initrd path, and kernel command-line parameters.

#
## DO NOT EDIT THIS FILE
#
## It is automatically generated by grub-mkconfig using templates
## from /etc/grub.d and settings from /etc/default/grub
#

#### BEGIN /etc/grub.d/00_header ###
...
#### END /etc/grub.d/00_header ###

#### BEGIN /etc/grub.d/05_debian_theme ###
...
#### END /etc/grub.d/05_debian_theme ###

#### BEGIN /etc/grub.d/10_linux ###
...
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' {
	recordfail
	...
	linux	/boot/vmlinuz-*-generic root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ro  quiet splash $vt_handoff
	initrd	/boot/initrd.img-*-generic
}
...
#### END /etc/grub.d/10_linux ###

#### BEGIN /etc/grub.d/20_linux_xen ###
...
#### END /etc/grub.d/20_linux_xen ###

#### BEGIN /etc/grub.d/30_os-prober ###
...
#### END /etc/grub.d/30_os-prober ###

#### BEGIN /etc/grub.d/30_uefi-firmware ###
...
#### END /etc/grub.d/30_uefi-firmware ###

#### BEGIN /etc/grub.d/40_custom ###
...
#### END /etc/grub.d/40_custom ###

#### BEGIN /etc/grub.d/41_custom ###
...
#### END /etc/grub.d/41_custom ###

You can scroll through the output to see the different menu entries and their configurations. Look for lines starting with menuentry. These define the options that appear in the GRUB boot menu.

This file is complex, and you don't need to understand every line right now. The key takeaway is that /boot/grub/grub.cfg is the file GRUB actually uses, and it's generated from /etc/default/grub and scripts in /etc/grub.d.

Click Continue to move on.

Inspect GRUB parameters in dmesg

In the previous steps, we examined the GRUB configuration files /etc/default/grub and /boot/grub/grub.cfg. We saw that /etc/default/grub contains the GRUB_CMDLINE_LINUX_DEFAULT variable, which specifies kernel parameters. These parameters are passed to the Linux kernel when it boots.

The dmesg command is used to display the kernel ring buffer messages. These messages contain information about the system's boot process, including the kernel command line parameters that were used.

Let's use dmesg to see the kernel command line parameters that were passed by GRUB during the boot of this virtual machine.

Type the following command in your terminal and press Enter:

dmesg | grep "Kernel command line"

Here's a breakdown of the command:

  • dmesg: Displays the kernel messages.
  • |: This is 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 "Kernel command line": This command searches for lines containing the exact phrase "Kernel command line" in the input it receives (from dmesg).

The output will show the kernel command line that was used to boot the system. It will look similar to this:

[    0.000000] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-*-generic root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ro quiet splash vt.handoff=7

You can see the parameters like quiet and splash which were likely defined in the GRUB_CMDLINE_LINUX_DEFAULT variable in /etc/default/grub. These parameters tell the kernel how to behave during boot. For example, quiet reduces the amount of output during boot, and splash enables a graphical boot screen.

Inspecting the kernel command line with dmesg is a useful technique for verifying that your GRUB configuration changes are being applied correctly and for troubleshooting boot issues related to kernel parameters.

You have now successfully explored the GRUB configuration and verified the kernel parameters using dmesg.

Click Continue to complete this lab.

Summary

In this lab, we learned how to check if GRUB settings are applied in Linux. We started by examining the primary GRUB configuration file, /etc/default/grub, using the cat command to understand its contents and the various parameters that control GRUB's behavior during the boot process.

By viewing the /etc/default/grub file, we gained insight into settings like the default boot entry, timeout values, and kernel command-line arguments. This initial step is crucial for understanding the intended GRUB configuration before verifying its application.