1. Overview

The Linux kernel manages hardware resources, schedules tasks, and provides essential services to other system components.

In this quick tutorial, we’ll explore how to get the kernel command-line parameters in the current running Linux system.

2. Introduction to Kernel Command-Line Parameters

The Linux kernel can accept command-line parameters to control various aspects of its behavior, such as specifying the root partition, enabling debug messages, disabling specific hardware drivers, setting boot delay, and more. The kernel command-line parameters are a set of arguments passed to the kernel at boot time.

Let’s see some common examples of kernel command-line parameters:

  • init – Specify the first process that should be executed after the kernel initializes
  • root – Specify the root file system that should be mounted during the boot process
  • quiet – Suppress all kernel messages during the boot process, except for critical errors
  • acpi – Control the Advanced Configuration and Power Interface (ACPI) settings
  • noapic – Disable the Advanced Programmable Interrupt Controller (APIC)
  • nomodeset – Disable kernel-mode setting, which can help with graphics card compatibility issues
  • debug – Enable kernel debugging and generate debug messages

Usually, we set the kernel command-line parameters in the configuration of the bootloader, such as GRUB or LILO. So, for example, we can boot Linux in command-line mode instead of GUI by adjusting kernel command-line parameters in GRUB.

Kernel command-line parameters are significantly helpful for troubleshooting and system performance tuning. So, they are an important tool for Linux administrators and developers.

Next, let’s see how we can get the kernel command-line parameters of the current boot.

3. From /proc/cmdline

There are several ways to get the kernel command-line parameters in a running Linux system. One of the most straightforward ways is to check the /proc/cmdline file. The /proc/cmdline file contains the entire command-line used to boot the currently running kernel. We can simply use the cat command to read its content:

$ cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-linux root=UUID=5ff0bc40-514c-4925-8d66-d6a0a9d6c850 rw ipv6.disable=1

In the example above, we can see that the root= parameter specifies the root filesystem. The “rw” parameter indicates that the system mounts the root device “read-write” on boot and ipv6.disable=1 disables IPv6. We didn’t pass many parameters to the kernel in this example.

However, some systems may have sophisticated parameters, for example:

$ cat /proc/cmdline 
coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_compat_alsa=0 snd_bcm2835.enable_hdmi=1  smsc95xx.macaddr=DC:A6:32:15:27:F8 vc_mem.mem_base=0x3ec00000 vc_mem.mem_size=0x40000000  console=ttyS0,115200 console=tty1 root=PARTUUID=f4481065-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait cgroup_memory=1 cgroup_enable=memory

4. Using the dmesg Command

The dmesg command allows us to examine or control the kernel ring buffer. The default action is to display all messages from the kernel ring buffer. Of course, the kernel command-line parameters are included.

We can pipe dmesg’s output to the grep command with the pattern “command line” to filter kernel command-line parameters:

kent$ sudo dmesg | grep 'command line'
[sudo] password for kent: 
[    0.062584] Kernel command line: BOOT_IMAGE=/boot/vmlinuz-linux root=UUID=5ff0bc40-514c-4925-8d66-d6a0a9d6c850 rw ipv6.disable=1

As the output above shows, the kernel command line is filtered out. It’s worth mentioning that we need superuser privilege to execute the dmesg command.

5. Conclusion

In this article, we first understood what kernel command-line parameters are. Then, we learned how to get the kernel command-line parameters in a running Linux system.

Understanding how to access and modify the kernel command-line parameters is an important skill for any Linux system administrator or developer, as it allows us to fine-tune a system’s behavior and performance.

Inline Feedbacks
View all comments