3

I have a cronjob running that checks for server updates, installs them one by one, and then checks if a reboot is needed. If a reboot is needed, the script will reboot the server.

The hardware clock is used at boot time, Takes a minute, before the system clock is used.

Before the switch to the system clock, the logs shows that the server is an hour or so behind, when it the server switches from hardware to system clock, the logs jump and hour or so ahead, which triggers the cron daemon, it noticed that the time already has passed for the server update script, and executes it again.

Which triggers a reboot loop, because the script was only meant to be executed once a week.

Excecuting hwclock --systohc syncs the system clock with the hardware clock, but it is not permanent. After a reboot, the time difference is off again.

My questions is

How do I permanently sync the system clock with the hardware clock?

output of timedatectl status:

      Local time: Tue 2018-08-28 12:05:37 CEST
  Universal time: Tue 2018-08-28 10:05:37 UTC
        RTC time: Tue 2018-08-28 10:05:37
       Time zone: n/a (CEST, +0200)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: yes
      DST active: yes
 Last DST change: DST began at
                  Sun 2018-03-25 01:59:59 CET
                  Sun 2018-03-25 03:00:00 CEST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2018-10-28 02:59:59 CEST
                  Sun 2018-10-28 02:00:00 CET

Warning: The system is configured to read the RTC time in the local time zone.
         This mode can not be fully supported. It will create various problems
         with time zone changes and daylight saving time adjustments. The RTC
         time is never updated, it relies on external facilities to maintain it.
         If at all possible, use RTC in UTC by calling
         'timedatectl set-local-rtc 0'.

  • CentOS Linux release 7.5.1804 (Core)
    • This is a VPS server.
  • Europe/Amsterdam
6
  • Could you include your timezone/DST details. Aug 28, 2018 at 8:40
  • @mr.spuratic done!
    – blade19899
    Aug 28, 2018 at 8:46
  • What's the system hardware? Some manufacturers' blade hardware has a feature that syncs the system clock of a blade server to the clock of the blade chassis management unit at each reboot. I know that it is enabled by default at least on Fujitsu blade hardware, but can be disabled in the blade BIOS settings.
    – telcoM
    Aug 28, 2018 at 9:10
  • @telcoM this is a VPS server.
    – blade19899
    Aug 28, 2018 at 9:29
  • IMHO, it seems that you have some trouble with timezone of the hardware clock. Is you hwclock set to UTC or local time? Please, show us the output of timedatectl status.
    – andcoz
    Aug 28, 2018 at 9:52

1 Answer 1

6

According to your timedatectl status:

  • your hardware clock (RTC) is set to UTC time (RTC time),
  • your system is set to evaluate your hardware clock as local time (RTC in local TZ).

As result, at boot, your system clock is set one hour late (your time zone without DST).

From man hwclock:

POSIX systems, like Linux, are designed to have the System Clock operate in the UTC timescale.

You can easily correct it executing:

timedatectl --adjust-system-clock set-local-rtc 0

The root of all evil is that RTC does not remember the TZ which it is set. Note that RTC time line has no TZ indication. When you keep the time in an hardware piece and the TZ in a file (/etc/adjtime as @mr.spuratic noted), it is easy to lost synchronization between the two information.

For sake of completeness, IMHO the only situation in which to keep hardware clock set to local is a dual boot machine with Windows.

2
  • /etc/adjtime is where this state is kept, it will be updated to record this. Aug 28, 2018 at 11:07
  • That is precisely why I came here, to keep clocks in sync across Linux and Windows. Thank you, sir.
    – Bus42
    Nov 12, 2021 at 1:14

You must log in to answer this question.

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