3

My RTC time on my Ubuntu 16.04 is going crazy. After a few minutes the RTC time is going totaly wrong.

The strange thing is, if I disable NTP Service (timedatectl set-ntp false and service ntp stop) and fix the time once (hwclock -w) the RTC time is always correct. The local time (the really correct time) is always correct.

My configuration:

  • Root Server with Hyper-V (Windows Server 2012 R2) with correct ntp time.
  • Time Sync in the Hyper-V VM settings is disabled. (Otherwise I got this "Time has been changed" message every 5 seconds at /var/log/syslog)
  • Guest: Ubuntu 16.04

Without NTP Service:

timedatectl
Local time: Fri 2017-03-03 12:07:35 CET
Universal time: Fri 2017-03-03 11:07:35 UTC
RTC time: Fri 2017-03-03 11:07:35
Time zone: Europe/Berlin (CET, +0100)
Network time on: no
NTP synchronized: no
RTC in local TZ: no

With NTP Service (service ntp start):

timedatectl
Local time: Fri 2017-03-03 12:09:15 CET
Universal time: Fri 2017-03-03 11:09:15 UTC
RTC time: Fri 2017-03-03 11:09:29
Time zone: Europe/Berlin (CET, +0100)
Network time on: no
NTP synchronized: yes
RTC in local TZ: no

and later (with NTP enabled):

timedatectl
Local time: Fri 2017-03-03 13:12:28 CET
Universal time: Fri 2017-03-03 12:12:28 UTC
RTC time: Fri 2017-03-03 12:52:58
Time zone: Europe/Berlin (CET, +0100)
Network time on: no
NTP synchronized: yes
RTC in local TZ: no

even later (with NTP enabled):

timedatectl
Local time: Fri 2017-03-03 13:42:16 CET
Universal time: Fri 2017-03-03 12:42:16 UTC
RTC time: Fri 2017-03-03 12:51:46
Time zone: Europe/Berlin (CET, +0100)
Network time on: no
NTP synchronized: yes
RTC in local TZ: no

Same thing happens if I use "timedatectl set-ntp true" instead of ntpd. This only happens on Hyper-V. My Ubuntu 16.04 on esxi didn't have this problem. Why NTP service Change the RTC time clock? How can I fix it?

The main problem is, that the RTC time is using at boot time and then the time is going backwards after boot. Some services have a problem with this and didn't work properly if this time jumps happens.

Jerico
  • 31
  • 2
  • 1
    Please refrain from spamming the same question on multiple SX sites. You asked the question on the ubuntu site: http://askubuntu.com/questions/889152/rtc-time-is-going-totally-wrong-after-a-few-minutes-16-04-hyper-v – dfc Mar 05 '17 at 20:41
  • Did you find a resolution? The askubuntu link above no longer works, and I'm having a similar issue with RTC clocks on HyperV, I just had one drift 76 minutes fast after 90 minutes of run (i.e. almost double), this on 18.04 and chrony, so a lot later. But only this server. – Linwood Oct 15 '19 at 03:00

2 Answers2

0

The issue is that Linux assumes RTC to store UTC time, which is then adjusted to the timezone set within OS, while Windows (including Hyper-V) assumes RTC to store local time which is almost always different from UTC+0. And by default Microsoft Hyper-V has "Synchronize guest time with host" hypervisor service flag enabled for all newly created VMs. This, combined with running NTP within guest, creates the scenario in which NTP thinks that RTC is off by several hours, and attempts to fix that issue by not just setting the clock to correct value (in guest), but also adjusting clock speed, as it assumes that RTC went forward or backward on its own, without any external influence. The proper solution would be to disable guest time synchronization altogether, and let NTP run inside guest to periodically fix any local clock discrepansies.

Vesper
  • 754
  • 1
  • 9
  • 29
0

You could try PTP timekeeping:

[...] To solve the problem, a solution was introduced in Linux-4.11: PTP devices for KVM and Hyper-V. These devices are not actually related to the PTP time synchronization protocol and don't work with network devices, but they present themselves as PTP (/dev/ptp*) devices, so they're consumable by the existing time synchronization software. [...]

https://opensource.com/article/17/6/timekeeping-linux-vms

http://manpages.ubuntu.com/manpages/trusty/man8/ptpd.8.html

Gerrit
  • 1,347
  • 7
  • 8