Better Time Synchronization with VirtualBox Guest Additions

The time synchronization using the VirtualBox Guest Additions is too gradual by default. One of my machines drifted until there was a discrepancy of almost 20 minutes. Apparently, 20 minutes is the threshold at which a hard resync is performed. But this isn’t what I expected from the Guest Additions. I expected the guest system time to track the host system time precisely, and it didn’t seem like this was happening. I also don’t want gradual resynchronization, as it just takes too long to shift the clock back into a usable state.

When the clock is seriously skewed, building software goes awry, because the make command starts detecting filestamps from the future, and other weird things.

According to the VirtualBox Manual, you can tune the time synchronization parameters by either setting properties on the virtual machine configuration using vboxmanage, or by specifying the parameters to VBoxService itself. I chose the latter option, though I’m sure the former is probably easier.

The startup file that controls VBoxService on Ubuntu is /etc/init.d/vboxadd-service. It is possible to edit this file to force more frequent synchronization, by changing the line:

daemon $binary > /dev/null


daemon $binary "--timesync-set-start --timesync-set-on-restore 1 --timesync-set-threshold 5000" > /dev/null

In addition, I pushed the niceness level of the task downwards, so that even under pressure, the VBoxService isn’t competing with normal tasks to do its job. In the same file, I changed the line:

start-stop-daemon --start --exec $1 -- $2


start-stop-daemon --start --nicelevel "-5" --exec $1 -- $2

For the impatient: Running the VBoxService command by hand will also do an immediate clock-sync, along with generating some output you would rarely see:

/etc/init.d$ sudo /usr/sbin/VBoxService --timesync-set-start
VBoxService 4.3.6 r91406 (verbosity: 0) linux.amd64 (Dec 18 2013 16:45:21) release log
00:00:00.001752 main Log opened 2014-02-09T12:38:04.424360000Z
00:00:00.002533 main OS Product: Linux
00:00:00.002776 main OS Release: 3.8.0-35-generic
00:00:00.003015 main OS Version: #52~precise1-Ubuntu SMP Thu Jan 30 17:24:40 UTC 2014
00:00:00.003255 main OS Service Pack: #52~precise1-Ubuntu SMP Thu Jan 30 17:24:40 UTC 2014
00:00:00.003498 main Executable: /opt/VBoxGuestAdditions-4.3.6/sbin/VBoxService
00:00:00.003499 main Process ID: 1864
00:00:00.003500 main Package type: LINUX_64BITS_GENERIC
00:00:00.004203 main 4.3.6 r91406 started. Verbose level = 0

In my case, the guest clock will now drift no more than 5 seconds before a hard-resync with the host clock.

5 thoughts on “Better Time Synchronization with VirtualBox Guest Additions”

  1. Thanks for the tip, I’ve been struggling to get proper timesync in a multiple vagrant setup for Ceph object storage, which has very strict time needs, clock skew of less than 0.05 sec already makes the cluster have issues. Using stratum1 ntp servers did not even fix this, as some of the VM’s kept on drifting. This patch solves all above issues, with a minor change to –timesync-set-threshold, changing that to 500 millisecs.

  2. Thank yooooooooou! Made the updates you suggested and no more timestamp warnings from make. I’d been trying to fix that for ages using answers on stackoverflow – should’ve realised it was a VirtualBox problem earlier..

  3. Is this no longer applicable for newer versions? I have Virtualbox 5.2.2, and installed the guest additions using the CD image from the host, but on my Ubuntu 16 guest I get this:

    cat: /etc/init.d/vboxadd-service: No such file or directory

    1. Just found the answer, /etc/init.d/vboxadd-service was actually located here for me: /opt/VBoxGuestAdditions-5.2.2/vboxadd-service

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.