Unix & Linux: How can dmesg content be logged into a file? (3 Solutions!!)
Channel: Roel Van de Paar
Date: 15/08/2020

Unix & Linux: How can dmesg content be logged into a file?


The Question: I'm running a Linux OS that was built from scratch. I'd like to save the kernel
message buffer (dmesg) to a file that will remain persistent between reboots.
I've tried running syslogd but it just opened a new log file, /var/log/
messages, with neither the existing kernel message buffer, nor any new messages
the kernel generated after syslogd was launched.
How can the kernel message buffer be saved to a persistent log file?

Solutions: Please watch the whole video to see all solutions, in order of how many people found them helpful

== This solution helped 17 people ==
You need to look at either /etc/rsyslog.conf or /etc/syslog.conf. If you have a
line early on such as:
*.* -/var/log/syslog
Everything, including the stuff from dmesg, should go to that file. To target
it better:
kernel.* -/var/log/dmesg
If that fails for some reason, you could periodically (e.g. via cron):
dmesg ＞ /var/log/dmesg
Depending on how big the dmesg buffer is (this is compiled into the kernel, or
set via the log_buf_len parameter) and how long your system has been up, that
will keep a record of the kernel log since it started.
If you want to write the dmesg output continuously to a file use the -w (--
follow) flag.
dmesg --follow ＞ mydmesg.log

With thanks & praise to God, and with thanks to the many people who have made this project possible! | Content (except music & images) licensed under cc by-sa 3.0 | Music: https://www.bensound.com/royalty-free-music | Images: https://stocksnap.io/license & others | With thanks to user rubynorails (https://unix.stackexchange.com/users/135610), user miluz (https://unix.stackexchange.com/users/46715), user Joe (https://unix.stackexchange.com/users/145124), user goldilocks (https://unix.stackexchange.com/users/25985), user Catalin Hritcu (https://unix.stackexchange.com/users/52045), user atevm (https://unix.stackexchange.com/users/150252), user Anthon (https://unix.stackexchange.com/users/33055), and the Stack Exchange Network (http://unix.stackexchange.com/questions/89227). Trademarks are property of their respective owners. Disclaimer: All information is provided "AS IS" without warranty of any kind. You are responsible for your own actions. Please contact me if anything is amiss at Roel D.OT VandePaar A.T gmail.com.