brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: dmesg -n stops kernel messages from flooding the console

Dmesg
~/tips/tip-dmesg-console-level

sudo dmesg -n 4

Keep kernel messages off your console screen while they still land in the log.

You’re logged in on the physical console of a server, or on a serial or IPMI console, and halfway through a command the kernel prints a USB or network message right across your screen. dmesg can turn that down.

sudo dmesg -n 4

-n (long form --console-level) sets which kernel messages still reach the console. Only messages more important than the level you give get printed, so 4 (warning) lets emergency, alert, critical and error messages through and keeps warnings and everything below off your screen. The man page’s own example is -n 1, which leaves only panic messages.

Nothing gets lost. The messages still go into the kernel log, so dmesg and journalctl -k show them like before. You can see the current value as the first number in:

cat /proc/sys/kernel/printk

If you want the console completely quiet for a moment, dmesg -D switches the printing off and dmesg -E turns it back on.

The caveat: it’s gone after a reboot. To keep it, add loglevel=4 to the kernel command line, or set kernel.printk in a file under /etc/sysctl.d/. And I wouldn’t go all the way down on a machine you troubleshoot from its console, because a crash message is exactly what you want to see there.

Further reading: dmesg(1) man page, Linux kernel docs: /proc/sys/kernel/printk

More Dmesg tips sudo dmesg -C sudo dmesg -x sudo dmesg -r > kernel.raw sudo dmesg -T | tail -30 All Dmesg tips (5) All topics

Link