Inspect kernel params in /proc/sys/kernel
In this step, we'll explore another way to view kernel parameters: the /proc/sys/kernel
directory. This directory provides a virtual file system interface to kernel variables. Each file in this directory represents a kernel parameter.
The /proc
directory is a special directory in Linux that provides information about running processes and the kernel. It's a virtual file system, meaning that the files and directories within it don't actually exist on the disk. Instead, they are dynamically created by the kernel when accessed.
To list the files in the /proc/sys/kernel
directory, open your terminal and use the ls
command:
ls /proc/sys/kernel
This command will display a list of files, each representing a kernel parameter. You'll see files like hostname
, domainname
, osrelease
, version
, and many others.
acpi_video_flags ctrl-alt-del dmesg hostname modules_disabled osrelease powersave-nap pty random realtime-max-usleep shmmax shmall shmmni sysrq tainted threads-max unknown_nmi_panic version yama
To view the value of a specific kernel parameter, you can use the cat
command on the corresponding file. For example, to view the system's hostname, use the following command:
cat /proc/sys/kernel/hostname
This will display the current hostname of the system.
labex
Similarly, to view the kernel version, use the following command:
cat /proc/sys/kernel/osrelease
This will display the kernel version.
5.15.0-76-generic
You can also use the sysctl
command to view these parameters, as we saw in the first step. For example, the following command is equivalent to cat /proc/sys/kernel/hostname
:
sysctl kernel.hostname
The /proc/sys/kernel
directory provides a wealth of information about the kernel's configuration and state. It's a valuable resource for system administrators and developers who need to understand and monitor the system's behavior.
It's important to note that while you can view these files, you typically need root privileges to modify them directly. However, using sysctl
is the preferred way to modify kernel parameters, as it provides a more controlled and consistent interface.