Keeping track of reboots with dmesg


9th February 2004

One of the things I want to keep track of is the status of the kernel and modules at reboot time. At boot time, most of the details are written to /var/log/messages, and can be accessed by viewing that file or by using dmesg. However, if I come back after a few weeks and want to check the status of the last boot, there's a fair chance that the information is gone. Lots of logs get written to /var/log/messages and the information just goes away.

Also, I wanted to keep track of kernel and module status in between reboots when I'm installing a new kernel or installing a new version of Slackware. The answer was fairly obvious, yet not so obvious that I saw it.

I spotted this technique in the newsgroup alt.os.linux.slackware. You can find the original messages dated around 11 December 2003. I take no credit for this simple technique, I just saw it and adapted it to my systems, and am writing this here so I don't forget it and can easily refer to it.

I add these lines to /etc/rc.d/rc.local:

NOW=`date +%Y%m%d.%H%M`
dmesg > /var/log/dmesg/dmesg.log.$NOW

And as root, I create a new directory /var/log/dmesg.

Once this is set up, at the end of every reboot, I get a dated file stored in /var/log/dmesg which contains the contents of dmesg as they were immediately at the end of the boot. I get to keep track of when my systems rebooted. If I'm fiddling with the kernel, I can diff subsequent reboots and see the changes. It's just a small thing, but gives me just that little bit more information to keep track of what my systems are doing.