How to check if a specific kernel compile option is enabled in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to determine if a specific kernel compile option is enabled in your Linux system. We will explore three common methods to achieve this.

First, you will use the zcat command to inspect the compressed kernel configuration file located at /proc/config.gz, which contains the options used during kernel compilation. Next, you will learn how to verify these options by examining the configuration files found in the /boot directory. Finally, you will discover how to inspect the kernel's compile logs using the dmesg command to gain further insight into the enabled features. By the end of this lab, you will be equipped with the skills to effectively check kernel compile options on your Linux system.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/TextProcessingGroup(["Text Processing"]) linux(("Linux")) -.-> linux/CompressionandArchivingGroup(["Compression and Archiving"]) linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/BasicFileOperationsGroup -.-> linux/less("File Paging") linux/TextProcessingGroup -.-> linux/grep("Pattern Searching") linux/CompressionandArchivingGroup -.-> linux/gzip("Gzip") subgraph Lab Skills linux/ls -.-> lab-558758{{"How to check if a specific kernel compile option is enabled in Linux"}} linux/cat -.-> lab-558758{{"How to check if a specific kernel compile option is enabled in Linux"}} linux/less -.-> lab-558758{{"How to check if a specific kernel compile option is enabled in Linux"}} linux/grep -.-> lab-558758{{"How to check if a specific kernel compile option is enabled in Linux"}} linux/gzip -.-> lab-558758{{"How to check if a specific kernel compile option is enabled in Linux"}} end

Check compile options with zcat /proc/config.gz

In this step, you will learn how to inspect the kernel configuration options that were used when your Linux kernel was compiled. This information is stored in a compressed file within the /proc filesystem.

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

The file we are interested in is /proc/config.gz. This file contains the kernel configuration options in a compressed format. To view its contents, we need to use a command that can decompress and display the file.

The zcat command is perfect for this. It's used to decompress and display the contents of gzipped files.

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

Now, type the following command and press Enter:

zcat /proc/config.gz

This command will decompress the /proc/config.gz file and print its contents to your terminal. You will see a long list of configuration options, each starting with CONFIG_. These options determine which features and drivers are included in your kernel.

For example, you might see lines like:

CONFIG_NET=y
CONFIG_PACKET=y
CONFIG_UNIX=y
## CONFIG_NET_KEY is not set
CONFIG_INET=y
  • CONFIG_NET=y means networking support is enabled.
  • CONFIG_NET_KEY is not set means a specific networking feature is not included.

Scrolling through this output can be overwhelming. You can use the less command to view the output page by page. To do this, we'll use a pipe (|). The pipe sends the output of one command as the input to another command.

Type the following command and press Enter:

zcat /proc/config.gz | less

Now you can use the arrow keys to scroll up and down, and press q to exit less.

This command is very useful for understanding exactly how your kernel was built and what capabilities it has.

Click Continue to proceed to the next step.

Verify options in /boot/config-*

In the previous step, you viewed the kernel configuration from /proc/config.gz. Another place where kernel configuration files are often stored is in the /boot directory.

The /boot directory contains files needed to boot the operating system, including the kernel itself and often the configuration file used to build it.

The configuration file in /boot is typically named config- followed by the kernel version. Since the kernel version can vary, we can use a wildcard (*) to match the file name.

First, let's list the files in the /boot directory to see if a config file exists there. Use the ls command:

ls /boot/

You should see a list of files, including one that starts with config- and is followed by a version number (e.g., config-5.15.0-105-generic).

Now, let's view the contents of this file. We can use the cat command to display the file's content. Remember to replace config-* with the actual file name you found in the previous ls output, or use the wildcard. Using the wildcard is more general.

Type the following command and press Enter:

cat /boot/config-*

This will display the kernel configuration options from the file in the /boot directory. You will notice that the content is very similar, if not identical, to the output you saw from zcat /proc/config.gz. This is because /proc/config.gz is often a compressed copy of the configuration file found in /boot.

Using cat on the file in /boot is another way to access the kernel configuration, especially if /proc/config.gz is not available or you want to see the uncompressed version directly.

Again, you can pipe the output to less for easier viewing:

cat /boot/config-* | less

Press q to exit less.

Understanding where to find the kernel configuration is important for troubleshooting and advanced system administration.

Click Continue to move on.

Inspect compile logs in dmesg

In the previous steps, you learned how to view the kernel configuration. Now, let's look at the kernel's message buffer, which contains messages produced by the kernel during boot and runtime. This can sometimes include information related to the kernel compilation or modules being loaded.

The dmesg command is used to examine or control the kernel ring buffer. The ring buffer stores messages from the kernel, which are often useful for debugging and understanding system events.

Type the following command in your terminal and press Enter:

dmesg

This will print a large amount of output to your terminal. These are messages from the kernel, including information about hardware detection, device drivers being loaded, and other system events that occurred since the system booted.

To find information related to the kernel version or compilation, you can pipe the output of dmesg to grep. grep is a powerful command-line utility for searching plain-text data sets for lines that match a regular expression.

Let's search for lines containing the word "Linux" to see the kernel version information.

dmesg | grep "Linux"

You should see output similar to this, showing the kernel version:

[    0.000000] Linux version 5.15.0-105-generic (...)

You can also search for other keywords that might be related to kernel modules or compilation options, although direct compilation logs are usually not found here. dmesg is more about runtime kernel messages.

For example, you could search for messages related to a specific driver or subsystem if you know its name.

Again, using less with dmesg is helpful for navigating the output:

dmesg | less

Press q to exit less.

While dmesg doesn't directly show the kernel compilation process itself, it provides valuable insights into the kernel that is currently running, including its version and loaded modules, which are determined by the compilation configuration you viewed in the previous steps.

Click Continue to complete this lab.

Summary

In this lab, you learned how to check if a specific kernel compile option is enabled in Linux. You explored the /proc filesystem, specifically the /proc/config.gz file, which stores the kernel configuration options used during compilation. You utilized the zcat command to decompress and display the contents of this file, and learned how to pipe the output to less for easier viewing. This process allows you to inspect the various CONFIG_ options and determine which features and drivers are included in your running kernel.