18

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?

migrated from serverfault.com Sep 3 '13 at 8:48

This question came from our site for system and network administrators.

  • Which syslogd are you running: sysklogd, busybox, inetutils, systemd, rsyslog, other? – Gilles Sep 3 '13 at 22:22
16

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
  • 4
    +1 It is probably worth mention that dmesg uses a ring buffer so that it doesn't grow without bound and is held within the kernel so that messages can be logged prior to things like the filesystem is even up. – msw Sep 3 '13 at 10:42
3

If you use systemd then you can get all the information from the systemd journal using journalctl -k. syslog and rsyslog are not necessary if you use systemd.

0

PopSicle does this I use the old msdos redirect and it is redricted into a .csv file which is opened in a spread sheet by LibreOffice Calc in terminal try something like this

dmesg > /path to where you want the file written/File-Name.csv 
dmesg > /media/joe/Data/Z-Back/Script-Files/Dmesg-Output.csv 

echo "Dmesg-to-CSV.sh"" the script file"

#!/bin/bash
echo "This is a shell script"  
SOMEVAR='I am done running dmesg and redirecting to /media/joe/Data/B-Back/Script-Files/Dmesg-Output.csv'  
echo "$SOMEVAR"  
dmesg > /media/joe/Data/Z-Back/Script-Files/Dmesg-Output.csv 

echo "Dmesg-CSV.desktop"" the icon file"

[Desktop Entry]
Encoding=UTF-8
Name=Dmesg-to-CSV.sh
Comment=Launch DirSyncPro
Exec=gnome-terminal -e /media/joe/Data/Z-Back/Script-Files/Dmesg-to-CSV.sh
Icon=utilities-terminal
Type=Application
Name[en_US]=Dmesg-CSV.desktop

echo "both the .sh file and .desktop file are stored in the same directory as the .csv output file"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.