Virtualization framework time out of sync

When running Linux in a VM, if I close the lid of my macbook, when I reopen it, for exemple, two hours later, the Linux VM time has "drifted" and is two hours in the past.

https://developer.apple.com/documentation/virtualization/running_linux_in_a_virtual_machine

Microsoft solves this issue on their Hypervisor with a RTC device /dev/ptp_hyperv, and configuring chrony to use it, see https://learn.microsoft.com/en-us/azure/virtual-machines/linux/time-sync#chrony

Linux KVM do the same : https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/virtualization_deployment_and_administration_guide/chap-kvm_guest_timing_management#sect-KVM_guest_timing_management-Host-guest-time-sync

It seems there is also a virtio_rtc module coming

Virtualizing macOS on macOS has AppleVirtualPlatformRTCPlugin setting time on the guest.

But how to get a Linux time in sync with

Answered by Engineer in 796990022

There is no support for time synchronization for Linux in Virtualization. There is a custom mechanism for macOS guests as you mentioned.

A fairly popular workaround is to re-sync the time every minute in Linux.

Can you please file a feature request for integrating VirtioRTC describing the use cases you have? This sounds like it could be a useful feature to consider.

There is no support for time synchronization for Linux in Virtualization. There is a custom mechanism for macOS guests as you mentioned.

A fairly popular workaround is to re-sync the time every minute in Linux.

Can you please file a feature request for integrating VirtioRTC describing the use cases you have? This sounds like it could be a useful feature to consider.

Created FB14465224 in Feedback Assistant

When testing a web software, or developing one, I create a VM to isolate each software, while on my macbook, which can sleep very often, so the time can drift many times per day

A cron each minute is a solution, but as often, polling is not the best way, making network call with ntp so often is definitively not optimised and earth-friendly

Purely as a theoretical suggestion, you might use an additional VZFileHandleSerialPortAttachment pair to communicate the time to the VM.

  • You create a named-pipe file to attach the fileHandleForReading to;
  • On the guest side you have a shell script in a loop similar to while IFS= read -r time <&3; do date -s "$time"; done to set the time;
  • On the host side you have a script that echoes out the time into the named pipe, every time the computer wakes up. This is possible through a launchd plist.
Virtualization framework time out of sync
 
 
Q