34

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?

1
  • Which syslogd are you running: sysklogd, busybox, inetutils, systemd, rsyslog, other? Commented Sep 3, 2013 at 22:22

3 Answers 3

23

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

The dmesg buffer is of limited size (this is compiled into the kernel, or set via the log_buf_len parameter), and when that is reached the oldest stuff will be dropped (the furthest it goes back is the most recent boot).

If you want to write the output continuously to a file use the -w (--follow) flag.

dmesg --follow > mydmesg.log

On a system using systemd-journald, you can also get the content with journalctl -k; most likely (depending on configuration) journald's buffer is much larger and will therefore retail messages for longer.

1
  • 6
    +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. Commented Sep 3, 2013 at 10:42
8

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"

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.