Linux – dmesg time vs system time time isn’t correct

debiandmesglinuxtimeunix

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 ?

Best Answer

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.