17.4. printk

printk is the most simple and widely used way of getting information from the kernel, so you should familiarize yourself with its basic configuration.

We use printk a lot in our kernel modules, and it shows on the terminal by default, along with stdout and what you type.

Hide all printk messages:

dmesg -n 1

or equivalently:

echo 1 > /proc/sys/kernel/printk

Do it with a Kernel command line parameters to affect the boot itself:

./run --kernel-cli 'loglevel=5'

and now only boot warning messages or worse show, which is useful to identify problems.

Our default printk format is:

<LEVEL>[TIMESTAMP] MESSAGE

e.g.:

<6>[    2.979121] Freeing unused kernel memory: 2024K

where:

  • LEVEL: higher means less serious

  • TIMESTAMP: seconds since boot

This format is selected by the following boot options:

  • console_msg_format=syslog: add the <LEVEL> part. Added in v4.16.

  • printk.time=y: add the [TIMESTAMP] part

The debug highest level is a bit more magic, see: Section 17.4.3, “pr_debug” for more info.