10

I hope that here is somebody that can help me with this strange problem.

I think that i know why it is happening but i don't know how to solve it. Maybe it is because the BIOS time isn't set correct or something like it. But i don't want to change the BIOS time of approximate 400+ servers. (Or change the BIOS batt)

root@spool:~# echo TEST > /dev/kmsg
root@spool:~# dmesg -T | tail -1
[Mon Feb 17 04:57:03 2014] TEST
root@spool:~# date
Mon Feb 17 11:45:17 CET 2014

The server is running ntp for time sync.

Anybody here that knows how to fix this problem in the OS?

Linux spool 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1+deb7u1 x86_64 GNU/Linux

Why, when echoing to /dev/kmsg, the date/time of my message in dmesg is not synchronized with system date/time ?

  • Are you sure your localtime file /etc/localtime is right? The syslog get time from localtime. – VictorLee Jun 13 '18 at 6:17
5

To verify your theory (which, by the way, is sound), execute the following as root:

hwclock --show

This will show you your hardware clock on the server you are executing the command.

To synchronise your hardware clock with your system-time (which is managed by ntp), run the following command:

hwclock --systohc --utc

The last argument (--utc) tells hwclock to store the time in hardware clock in coordinated universal time.

Additionally, please keep in mind that man page for dmesg(1) say the following, so the behaviour you are experiencing is documented and valid:

   -T, --ctime
          Print human-readable timestamps.

          Be aware that the timestamp could be inaccurate!  The time
          source used for the logs is not updated after system
          SUSPEND/RESUME.
  • 1
    Thanks for your answer. But didn't work unfortunately... What i did is the following: root@spool:~# hwclock --show Mon Feb 17 20:30:14 2014 -0.985068 seconds root@spool:~# hwclock --systohc --utc root@spool:~# echo TEST > /dev/kmsg root@spool:~# dmesg -T | tail -1 [Mon Feb 17 13:50:14 2014] TEST root@spool:~# date Mon Feb 17 20:30:46 CET 2014 – g00gle Feb 17 '14 at 19:31
  • Well, dmesg -T does not guarantee the correctness of the timestamp (according to documentation), so use a proper logging daemon (e.g. klogd) and you will get correct timestamps for kernel messages. – galaxy Feb 17 '14 at 20:01
  • 1
    So there is no solution for the wrong timestamps in dmesg ? – g00gle Feb 18 '14 at 9:16
  • AFAIK, no, there is not. Moreover, this -T option to dmesg is quite a recent addition (by Debian?) and the majority of Linux distros don't know about such an option. Why it's a deal breaker for you? I've provided a solution re: how to get proper timestamps for kernel messages (i.e. klogd). – galaxy Feb 18 '14 at 9:36
  • 1
    I have the same issue on my server and can definitely rule out that the machine was ever Suspended/Resumed. Is there any other reason why the timestamp may be off? (ntp and hardware time are correct and have always been) – Daywalker Mar 30 '18 at 9:51
6

dmesg just prints the kernel ringbuffer which logs messages with uptime in seconds from being started as timestamp.

So if you use the -T option all this uptime values are just added to the date your system was booted. If you had times sleeping in suspend or resume, they are lost, so in this cases -T option is not useful, as date/time values are not right then and back in past.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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