RTC time is going totally wrong after a few minutes (Ubuntu 16.04 + Hyper-V)

clock-synchronizationhyper-v-server-2012-r2timeubuntu-16.04virtual-machines

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.

Best Answer

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