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 -C empties the kernel buffer so a test starts from nothing

Dmesg
~/tips/tip-dmesg-clear-before-test

sudo dmesg -C

Clear old messages, reproduce a problem and read only what it produced.

When I can trigger a problem on demand, I want a log that contains that one attempt and nothing from before it. Clearing the buffer first gives exactly that.

sudo dmesg -C

Now reproduce the fault, for example load the driver or start the program that fails. Then read the whole buffer:

sudo dmesg > attempt.txt

Everything in that file happened after the clear. It is short enough to read from top to bottom and easy to attach to a bug report. Run the same steps again after changing a setting, save to a second file, and compare:

diff <(cut -d']' -f2- attempt.txt) <(cut -d']' -f2- attempt2.txt)

The cut removes the timestamps, which would otherwise make every line differ. There is also dmesg -c with a lowercase c, which prints the messages and clears them in one go.

Warning: this throws away what is in the kernel ring buffer, including messages from startup that you might want later. On many distributions the journal has already stored a copy, which you can read with journalctl -k, but check that before you rely on it. On a shared server, tell the others, since someone else may be looking for those lines.

Further reading: dmesg man page

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

Link