How to improve VirtualBox guest time synchronisation after host sleeps/suspends

Paul Wilkinson

2023-06-15

Introduction

If you find the guest system time greatly out of sync after resuming from suspend, it could be because the VirtualBox Guest Additions default parameters are too lenient. You can change them as described in My solution below.

Table of Contents

The symptoms

When the following events occur:

the guest’s system time will usually be behind the host’s system by however long the host was in the sleep state, and it often won’t get corrected for several minutes. This can cause confusion, e.g. log entries in the guest won’t be what the user expects.

Similar issues occur if you pause the guest for a while.

The root cause

VirtualBox Guest Additions default threshold for doing a “big jump” time correction (versus slowly slewing the clock) is, IMHO, too high: deltas of 20 minutes1.

My solution

My configuration

Other versions could also be affected.

What about NTP / systemd-timesyncd ?

The guest’s systemd-timesyncd (systemd’s NTP client) has a more stringent threshold (0.4 seconds) for “big jump” time correction but it can take up to 30 minutes before it checks for a delta, which is too long for this situation[^2].

NTP on the guest isn’t the right tool to use in this situation. It’s better suited for correcting slow drift on a real system, not for a guest VM running on a host which is already (hopefully) correcting for drift.


  1. See https://docs.oracle.com/en/virtualization/virtualbox/7.0/user/AdvancedTopics.html#changetimesync documentation for --timesync-set-threshold. Anecdotally, it might be even higher, I’ve seen > 1 hour deltas remain uncorrected for several minutes. Possible bug? ↩︎


Questions or comments can be sent to [email protected]