kernelthread.com

How to see the kernel configuration?

What is the kernel configuration?

By using the phrase the kernel configuration, you have probably made the question a bit too open ended.

Kernel/System configuration could mean quite a few things, depending on whether it is run-time, compile-time, idle-time or just-in-time or just any other time. Let us look at some important configuration concepts.

Configuration for kernel compilation

One may have generated this by running some flavor of "make config" (config, menuconfig, xconfig ...) Assuming that the Linux kernel sources reside in /usr/src/linux, you can look at this configuration in the file /usr/src/linux/.config. Here is an example portion of the .config file:

... CONFIG_BLK_DEV_IDEDISK=y ... CONFIG_BLK_DEV_LOOP=m ... # CONFIG_BLK_DEV_MD is not set ...

This tells you that the enhanced IDE disk driver would be compiled in, the loop device driver would be compiled as a module, and the multiple devices driver would not be compiled, etc. Of course, one may not be familiar with what these CONFIG_FOO_BAR stand for, so as a reference look in the file /usr/src/linux/Documentation/Configure.help.

POSIX style sysconf

It is possible to get configuration information (like minimal and maximal values, certain kernel parameters) at runtime. See sysconf(3). Also, some file specific information may be obtained using pathconf(3) and fpathconf(3). Further, statfs(2)and fstatfs(2) would provide certain filesystem related information. The man pages of these calls are nicely detailed.

Linux/4.4BSD style sysctl

The /proc philosophy of housing tunable kernel parameters has worked well, so far, IMHO. One may use sysctl(2) to read and write such parameters. 4.4BSD has had something similar (sans the /proc business) for long. The bottomline: instead of calling sysctl(2) yourself, you can do pleasantly (blatantly?) simple stuff like the following:

echo 1 > /proc/sys/net/ipv4/ip_forward

The above would switch on IP forwarding, in this example. BSD doesn't show this "state tree" (of parameters/values) in /proc, but relies on plain old sysctl (using a sysctl(8) command line utility) to modify/read information, much similar to the way one uses a MIB in SNMP (actually, this is a MIB, technically speaking). Thus, in FreeBSD, you would say:

sysctl -w a.b.c.d=value

In the above example, a.b.c.d is the hierarchical path to a MIB variable, like net.tcp.something. This is not an uncommon way of maintaining kernel/system configuration, and surely, the ubiquitous Windows also uses a hierarchical database called the "registry", with the added requirement that upon useful changes to it, the system be rebooted.

As would be obvious, the /proc mirroring of the sysctl tree on Linux means you can simply browse the /proc hierarchy (using cat, sure), and find out (un)interesting things about your hardware and software. As an example, those running SPARC/Linux can have a nice view of the Sun OpenPROM stuff courtesy the openpromfs loadable module, which introduces a /proc entry for the openprom directory.

An Afterthought: UNIX (and (look|work)alikes) have always thrived on the "everything is a file" philosophy. Everyone likes the /proc filesystem, eh. The Plan-9 guys (Ritchie, Thompson, Winterbottom et al) have pushed the concept further, and the Inferno OS from Bell Labs has not only devices, but even device drivers as files. No, I am not digressing on that right now, but I just mentioned it to whet the technical appetite of those interested.