How to check if a kernel boot option is enabled in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check if a specific kernel boot option is enabled in Linux. We will explore three key methods to achieve this.

First, you will use the cat /proc/cmdline command to view the command line arguments passed to the kernel during the current boot session. Next, you will examine the GRUB configuration file located at /etc/default/grub to understand where some of these boot options are configured. Finally, you will inspect the boot logs using the dmesg command to see how the kernel interpreted and applied the boot options. By completing these steps, you will gain practical skills in diagnosing and understanding your Linux system's boot process.


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/BasicFileOperationsGroup -.-> linux/less("File Paging") linux/TextProcessingGroup -.-> linux/grep("Pattern Searching") subgraph Lab Skills linux/cat -.-> lab-558719{{"How to check if a kernel boot option is enabled in Linux"}} linux/less -.-> lab-558719{{"How to check if a kernel boot option is enabled in Linux"}} linux/grep -.-> lab-558719{{"How to check if a kernel boot option is enabled in Linux"}} end

Check boot options with cat /proc/cmdline

In this step, we'll explore how to view the boot options used when your Linux system started. This information is stored in a special file within the /proc filesystem.

The /proc filesystem is a virtual filesystem in Linux that provides information about processes and other system information. It doesn't contain real files on your disk but rather provides a window into the kernel's data structures.

The file we're interested in is /proc/cmdline. This file contains the command line arguments passed to the kernel at boot time. These arguments can influence how the kernel behaves and what hardware it detects.

To view the contents of this file, we'll use the cat command. The cat command is a simple utility used to display the content of files.

Open your terminal if it's not already open. You can do this by clicking the Xfce Terminal icon on the left side of your desktop.

Now, type the following command and press Enter:

cat /proc/cmdline

You will see output similar to this:

BOOT_IMAGE=/boot/vmlinuz-... root=UUID=... ro console=ttyS0,... quiet splash vt.handoff=7

The exact output will vary depending on your system's configuration, but it will show the kernel image being booted (BOOT_IMAGE), the root filesystem location (root=), and other options like ro (read-only filesystem initially), quiet, and splash.

Understanding these boot options can be helpful for troubleshooting boot issues or configuring specific kernel behaviors.

Remember, /proc/cmdline is a dynamic file generated by the kernel, so its content reflects the current boot session.

Click Continue to proceed to the next step.

Verify GRUB config with cat /etc/default/grub

In the previous step, we looked at the command line arguments passed to the kernel after it has started. Now, let's look at where some of those arguments might originate: the GRUB configuration file.

GRUB (GRand Unified Bootloader) is a boot loader. Its main job is to load the operating system kernel into memory and pass control to it. The GRUB configuration file determines the boot menu options, default operating system, and kernel parameters.

The primary configuration file for GRUB on many Linux systems is /etc/default/grub. This file contains settings that are used to generate the actual GRUB boot menu configuration.

We'll use the cat command again to view the contents of this file.

Open your terminal if it's not already open.

Type the following command and press Enter:

cat /etc/default/grub

You will see output similar to this:

## If you change this file, run 'update-grub' afterwards to update
## /boot/grub/grub.cfg.
## For full documentation of the options in this file, see:
##   info -f grub -n 'Simple configuration'

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
#GRUB_GFXPAYLOAD_LINUX=keep

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

## The resolution used on graphical terminal
## needs to be in the format e.g. 640x480 or 800x600 or 1024x768
## and your graphics card needs to support it. A list of all available resolutions can
## be found with 'videoinfo' command in grub.
#GRUB_GFXMODE=640x480

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

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

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

Look for the line that starts with GRUB_CMDLINE_LINUX_DEFAULT. The options listed here (like "quiet splash") are often passed to the kernel at boot time, and you might have seen them in the output of cat /proc/cmdline in the previous step.

This file is important because it allows you to configure default kernel parameters without having to type them manually every time you boot.

Important Note: If you were to make changes to this file on a real system, you would typically need to run sudo update-grub afterwards to apply the changes to the actual boot configuration file (/boot/grub/grub.cfg). However, in this lab environment, we are just inspecting the file.

Click Continue to move on.

Inspect boot logs with dmesg

In this final step, we'll look at the kernel ring buffer messages using the dmesg command. The kernel ring buffer stores messages from the kernel, including information about hardware detection, device drivers, and system events that occur during the boot process.

The dmesg command is used to display these messages. It's a crucial tool for diagnosing hardware issues or understanding what happened during system startup.

Open your terminal if it's not already open.

Type the following command and press Enter:

dmesg

This command will output a potentially very long list of messages. These messages are generated by the kernel as it initializes and interacts with the system's hardware and software.

You will see output similar to this (the exact output will vary greatly):

[    0.000000] Linux version ... (buildd@lcy02-amd64-...) (gcc-...) #...-Ubuntu SMP ...
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-... root=UUID=... ro console=ttyS0,... quiet splash vt.handoff=7
[    0.000000] KERNEL supported cpus:
[    0.000000]   Intel GenuineIntel
[    0.000000]   AMD AuthenticAMD
...
[    1.234567] usbcore: registered new interface driver usbfs
[    1.234567] usbcore: registered new interface driver hub
[    1.234567] usbcore: registered new device driver usb
...

Notice that the output includes the kernel version and the command line arguments, similar to what we saw in /proc/cmdline.

Since the output of dmesg can be extensive, it's often useful to pipe it to a pager like less or more to view it screen by screen.

Try this command:

dmesg | less

Now you can use the arrow keys to scroll up and down through the output. Press q to exit less.

You can also filter the output using grep to search for specific keywords, like "error" or the name of a hardware device.

For example, to see messages related to USB devices:

dmesg | grep -i usb

This command will show only the lines containing "usb" (case-insensitive due to the -i flag).

Exploring the dmesg output is a fundamental skill for Linux system administration and troubleshooting.

Click Continue to complete this lab.

Summary

In this lab, we learned how to check if a kernel boot option is enabled in Linux by examining the /proc/cmdline file. This file provides a dynamic view of the command line arguments passed to the kernel during the current boot session, offering insights into how the system started and its initial configuration.

We also began to explore the source of these boot options by looking at the GRUB configuration file, /etc/default/grub, which is a key location for defining kernel boot parameters before the system even starts.