2

This is still related to my yesterday thread, so there's alert or maybe it's just log that displayed on my terminal on /dev/tty1. Ofcourse it's annoying because it's displayed in my bash prompt, so whenever I want input something, my input has been overwrite with that output. It came printed out periodically maybe about 3 second. So you can see how it's annoying

My terminal is moreless looks like this:

root@LFS:# echo "Hey get out of there"clocksource: timekeeping watchdog on CPU0: acpi_pm wd-wd readback delay of 643744ns
clocksource: wd-tsc-wd read-back delay of 182144ns, clock-skew test skipped!
clocksource: timekeeping watchdog on CPU0: acpi_pm wd-wd readback delay of 643744ns
clocksource: wd-tsc-wd read-back delay of 182144ns, clock-skew test skipped!
clocksource: timekeeping watchdog on CPU0: acpi_pm wd-wd readback delay of 643744ns
clocksource: wd-tsc-wd read-back delay of 182144ns, clock-skew test skipped!
...

I suspect this is not because of clocksource, but dmesg output. Because when I command dmesg. It display same. But whenever I use /dev/pts There's no annoying output or alert that came periodically, I tested it when I login SSH in my LFS sistem.

So how to prevent dmesg log displayed to /dev/tty1

Update: Inside /proc/cmdline

root@LFS:~# cat /proc/cmdline
BOOT_IMAGE=/boot/vmlinuz-5.16.9-lfs-11.1 root=/dev/sda1 ro
2
  • What is the contents of /proc/cmdline? Commented May 20, 2022 at 14:36
  • @icarus I updated it Commented May 20, 2022 at 14:59

1 Answer 1

3

You can disable console output by reducing the console loglevel. For example, to disable all output by reducing the console loglevel to 0:

# sysctl kernel.printk='0 4 0 5'

kernel.printk takes four arguments:

  1. The console loglevel, which controls which messages will be displayed on the console (this is what you mostly care about);
  2. The default message loglevel for any messages which don't already have a loglevel set;
  3. The minimum console loglevel allowed, which clamps the console loglevel to a minimum;
  4. The default console loglevel (currently unused in code).

You can persist this in /etc/sysctl.conf, or /etc/sysctl.d/.

You can also use dmesg to do this using dmesg:

# dmesg -n1

From man dmesg:

-n, --console-level level: Set the level at which messages are logged to the console. The level is a level number or abbreviation of the level name. For example, -n 1 or -n alert prevents all messages except emergency (panic) messages from appearing on the console. All levels of messages are still written to /proc/kmsg, so syslogd(8) can still control exactly where kernel messages appear. When the -n option is used, dmesg will not print or clear the kernel ring buffer. For all supported levels see --help output.

You can also tweak this on the kernel command line by passing loglevel=N, see Documentation/admin-guide/kernel-parameters.txt. The option quiet is also available -- which level it actually sets depends on the value of CONFIG_CONSOLE_LOGLEVEL_QUIET, set at compile time.


Per-console loglevels

As an aside, after my patches to make console loglevel per-console get merged into the kernel, one will be able to reduce or increase the loglevel present for a particular class of consoles directly instead of affecting the whole system using controls in sysfs:

% ls -l /sys/class/console/ttyS/
total 0
lrwxrwxrwx 1 root root    0 May 20 14:40 subsystem -> ../../../../class/console/
-r--r--r-- 1 root root 4096 May 20 14:41 effective_loglevel
-r--r--r-- 1 root root 4096 May 20 14:41 effective_loglevel_source
-r--r--r-- 1 root root 4096 May 20 14:41 enabled
-rw-r--r-- 1 root root 4096 May 20 14:41 loglevel
-rw-r--r-- 1 root root 4096 May 20 14:40 uevent

The format is still a little in flux, but it will likely look similar to this when it gets merged in the next few kernel releases. kernel.printk will also likely be deprecated in favour of more granular controls.

See Documentation/admin-guide/per-console-loglevel.rst in the patch for more information.

8
  • dmesg: unknown level 0 Commented May 20, 2022 at 14:56
  • ls: cannot access /sys/class/console/ttyS/: No such file or directory Commented May 20, 2022 at 15:01
  • @MuhammadIkhwanPerwira As I said, the per-console loglevel controls are in my proposed patch which will land in the next few kernel versions, they're not upstream yet. And strangely yes, klogctl() seems to only take down to loglevel 1, whereas elsewhere we're perfectly happy with 0. For now you can use sudo dmesg -n1 which will reduce the number of messages dramatically. Commented May 20, 2022 at 15:02
  • sysctl -a | grep kernel.printk give me output, kernel.printk=7 4 1 7. This is happened if I reboot, so does it mean I must execute sysctl kernel.printk='0 4 0 5' everytime after I reboot OS?. No, I think I must put it in init.d as bootscript? Commented May 20, 2022 at 15:08
  • 1
    @MuhammadIkhwanPerwira As mentioned in the answer, you can persist it in /etc/sysctl.conf, or /etc/sysctl.d (with systemd). See man 5 sysctl.conf. Your init system then needs to load the sysctls. If you are running a very bare bones distro, you need to hook up to sysctl -p. Commented May 20, 2022 at 15:13

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.