4

We have RHEL server version 7.2 and we noticed that dmesg files from previous sessions under /var/log are not created

what we have under /var/log are only

ls -ltr | grep dmesg

-rw-r--r--  1 root   root    123011 Jan  3 04:03 dmesg

instead to get like:

    -rw-r--r--  1 root   root    123011 Jan  3 04:03 dmesg.0
    -rw-r--r--  1 root   root    123011 Jan  2 04:03 dmesg.1
    -rw-r--r--  1 root   root    123011 Jan  1 04:03 dmesg.2
.
.
.

what is the configuration that enable to save the old kernel messaged in backup files?

1
  • I just started a bounty on this, as I have the same question. I have a laptop system that is not waking after suspend and would very much like to be able to review the dmesg log from the previous session. I am personally using Parabola (Arch variant).
    – Time4Tea
    Aug 28, 2021 at 12:01

1 Answer 1

2
+50

I am not sure whether the solution below solves your problem, because it seems too easy (given your rep). But here we go:

If you have Storage=auto in /etc/systemd/journald.conf (which is the default in most installations I have seen), you just should create the directory /var/log/journal. With that setting, systemd-journald stores the logs in that directory if it exists, but stores the logs only in memory if it doesn't (and of course forgets them when shutting down). After having created the directory, you should execute systemd-tmpfiles --create --prefix /var/log/journal and restart systemd-journald.

Probably you can configure systemd-journald to use another location for the log files, but this is beyond my (current) knowledge (I never needed to do so and thus didn't research the necessary steps).

If you have Storage=persistent in /etc/systemd/journald.conf, /var/log/journal should be created automatically if needed.

For the sake of completeness, Storage=volatile means that the log data will only be stored in memory (and will be forgotten when shutting down), and Storage=none prevents any storage at all. You'll have to avoid these two if you want to see the logs from previous boots.

All of these setting are explained nicely in man journald.conf.

Please note that the solution outlined above relates to systemd, and thus is appropriate for the OP, because RHEL 7.2 is based on systemd.

If you insist in having a backup of old boot logs (although you already can view them using the standard configuration), you could simply issue journalctl -b <N> > demsg.<N>, e.g. journalctl -b 1 > dmesg.1 to save the oldest recorded boot log into file dmesg.1.

Therefore, the answer to your question (what is the configuration that enable to save the old kernel messaged in backup files) is:

  • I am not aware of any configuration setting to do that based on the dmesg files.
  • Of course, you can write a script to rotate the dmesg files, and let it run after each startup or before each shutdown.
  • But you can achieve your goal in a better (easier) way by following the procedure I have outlined above.

Unfortunately, the solution is not appropriate for the person who spent the bounty: It won't work with OpenRC because OpenRC isn't based on systemd (if I got the bounty statement right). In OpenRC, there may be other methods to solve the problem, but since I have never heard of it, I can't help there.

Reference:

https://gist.github.com/JPvRiel/b7c185833da32631fa6ce65b40836887

10
  • Ok, so you think dmesg log rotation can't be done in OpenRC at all, because it relies on systemd-journald (and OpenRC has no equivalent)?
    – Time4Tea
    Aug 31, 2021 at 11:05
  • No, that's not what I wanted to say. I just wanted to point out that the solution I have shown won't work with OpenRC, because that solution is based on systemd. I really do not know anything about OpenRC, so I can't tell whether there are other methods to achieve what you want. Perhaps you could configure logrotate to rotate dmesg after startup, or you could write your own script which does this, and put it in some file which gets executed when the multiuser runlevel is reached, or ... but I really don't know. My knowledge is restricted to Debian which I use on several machines.
    – Binarus
    Aug 31, 2021 at 14:26
  • so I looked at this on another system I have that is using systemd. The /var/log/journal folder was already present; however, there don't seem to be any dmesg files at all, either in /var/log or in the journal folder. I also tried setting Storage=auto in /etc/systemd/journald.conf, but it didn't seem to help either. I'm a bit confused.
    – Time4Tea
    Sep 2, 2021 at 1:57
  • 1
    systemd-journald places the logs in a subdirectory of /var/log/journal. The subdirectory and the log files in it have long, cryptic names (sort of GUIDs). The log files are in binary format and thus are not appropriate for direct reading, e.g. in a text editor. Instead, you read them via journalctl: journalctl -b <N>, where N is the number of the boot process you want to investigate. Basically, 1 shows the first boot process recorded, 2 the second and so on. Negative numbers have other effects. For details, see man journalctl.
    – Binarus
    Sep 2, 2021 at 7:01
  • 1
    And if there are no log files at all in /var/log/journal, you may have to set Storage=persistent in /etc/systemd/journald.conf. For details, see man journald.conf where the different possible values for the Storage stanza are explained quite at the beginning.
    – Binarus
    Sep 2, 2021 at 7:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .