How to sync time on host wake-up within VirtualBox

clockvagrantvirtual machinevirtualbox

I am running an Ubuntu 12.04-based box inside of Vagrant using VirtualBox. So far, everything is fine – except for one thing:

Let's assume that the VM is running. Then, the host goes to standby-mode. After waking it up again, the VM is still running, but its internal clock continues where it stopped when the host went down. So this basically means: Put the host to sleep for 15 minutes, wake it up again, then the VM's internal clock is 15 minutes late.

How can I fix this (setting the time manually is not an option for obvious reasons ;-))? Is there a way to run a script inside of a Vagrant VM whenever the host system changes its state?

I've read in the documentation that by default the VirtualBox Guest Additions sync the time with the host every 10 seconds. Apparently this is not happening, but I can not find any place where it is disabled. So any ideas?

PS: The Guest Additions are installed and match the version of VirtualBox being used.

Best Answer

The documentation lacks some details here.

What VirtualBox does every 10 seconds is just slight adjustement (something like 0.005 seconds). Only when the time difference reaches a threshold (20 minutes by default) a "real" resync is done.

You can reduce the thresold (i.e. to 10 seconds) with the following command:

VBoxManage guestproperty set <vm-name> "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold" 10000