Debian – Why doesn’t the Debian Hyper-V guest update time after host wakes up from sleep

debianhyper-vvirtualization

I have a Windows 10 physical (laptop) host with Hyper-V installed and enabled and I am having a problem where for a rather vanilla Debian 9 guest installation, the clock isn't updated after the host is put to sleep for a while and then is waken back up again (I assume the guest is suspended with the host).

As far as I understand, this problem should be trivially handled by Hyper-V integration services, which are enabled both in the virtual machine settings (all integration services enabled) and in the guest (all the hv_* modules are loaded), and where one of the services synchronizes time and makes sure it stays up to date.

So, why doesn't it work in my case? I don't have NTP installed and I don't want to, partially on principle (to troubleshoot the problem with Hyper-V specifically) and partially because the guest must work without Internet connection and remote host services. My host timezone is setup to UTC explicitly (I roam a lot with the laptop and have neither need nor wish to statically associate the guest with a particular timezone), and use TZ variable as needed instead.

I've read a bunch of pages at Microsoft's and some Altaro articles which seemed very informed yet failed to enlighten me on this. I also have read a number of answers on Stack Exchange sites, where half recommend using NTP and other half are mostly about something else or just do not produce desired advice.

I understand that there is perhaps some signal that doesn't fire on the guest when the host gets back from sleep (as it would if you'd put the guest to sleep through ACPI, for instance), but shouldn't this be a solved problem?

What and where can I troubleshoot to make sure I can reliably close the lid on the laptop (putting it to sleep) and expect to come back to my guest with an up-to-date timestamp?

Best Answer

  • Check this: https://github.com/clearlinux/distribution/issues/39

    A working fix is to disable all other time services and use chrony, than configuring only the LIS hyperv timesource ptp0.

    Ensure the LIS time-source is available via:

    ls /sys/class/ptp
    ptp0
    
    cat /sys/class/ptp/ptp0/clock_name 
    hyperv
    

    Now install chrony for your distro and check the config location, than create the config that corresponds to your ptp? device location.

    /etc/chrony.conf:

    refclock PHC /dev/ptp0 trust
    makestep 1 -1
    

    This will allow chrony to correct the systemtime via the hyperv ptp0 source in a single large step.

    The poll time can be lowered to 4 seconds (power of 2) via:

    refclock PHC /dev/ptp0 trust poll 2
    

    PS: It seems this is a bug/oversight in hyperv/LIS.

  • Related Question