How to view Linux kernel parameters for currently booted system

last updated in Categories , , , ,

How do I display or view Linux kernel parameters for currently running/booted kernel? How can I see Linux kernel command line parameters?

To display the Linux kernel command line parameters given for the current booted system use any one of the following Linux commands:
sysctl -a
sysctl -a | more
sysctl -a | grep 'something'
cat /proc/cmdline

How to view Linux kernel parameters using /proc/cmdline

On Linux, one can use a boot manager such as lilo or grub. One can pass arguments or parameters to the Linux kernel at boot time. Often you need to configure grub. All such parameters stored in /proc/cmdline file. To display/view current kernel parameters use the cat command:
cat /proc/cmdline
Sample outputs:

BOOT_IMAGE=/boot/vmlinuz-4.15.0-42-generic root=/dev/sda ro console=tty0 console=ttyS0,19200n8 splash

The above entry from /proc/cmdline file shows the parameters passed to the kernel at the time it is started. I booted my Linux server using /boot/vmlinuz-4.15.0-42-generic kernel image. My hard disk named /dev/sda act as root device to find /boot/vmlinuz-4.15.0-42-generic. Further, I configured serial console access via tty0/ttyS0 and speed set to 19200n8.

See Linux kernel parameters

A freshly booted Linux system can use the following command for the same purpose:
dmesg | grep "Command line"
Sample outputs:

[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-4.19.8 root=UUID=2381eff1-9677-4a04-9faa-323247ec2f83 ro quiet splash vt.handoff=1

How to display Linux kernel parameters or arguments using the sysctl

Sometimes you need to set up or update your Linux kernel parameters. The default values for particular kernel parameters on Linux may not be sufficient for running software. Often Linux kernel tunned using the sysctl command.

How to see all kernel parameters

Run the following sysctl command:
sudo sysctl -a
Use the grep command or more command as pager/filter for sysctl:
sudo sysctl -a | more
sudo sysctl -a | less
sudo sysctl -a | grep 'foo'
sudo sysctl -a | grep net.ipv4.ip_forward

How to view Linux kernel parameters using cmdline

How to modify Linux kernel parameters

Edit the /etc/sysctl.conf file or other files in /etc/sysctl.conf.d/ directory. For example, use a text editor such as nano command/vim command:
$ sudo vi /etc//etc/sysctl.conf.d/my-security.conf
Append the following settings:

## Reboot the machine soon after a kernel panic
kernel.panic=10
 
## Addresses of mmap base, heap, stack and VDSO page are randomized
kernel.randomize_va_space=2
 
## Ignore bad ICMP errors
net.ipv4.icmp_ignore_bogus_error_responses=1

Save and close the file in vim. Finally, run the following command load in sysctl settings:
$ sudo sysctl -p

Conclusion

This page explained how to check what are the current Linux kernel parameter settings using the sysctl command and /proc/cmdline file. For more info see:

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Start the discussion at www.nixcraft.com