How to stop the clock in a VirtualBox virtual machine from drifting
July 1, 2016 Leave a comment
I found that the clock in a VirtualBox virtual machine was drifting significantly from real time. As shown below, it is possible to synchronise the clock in a virtual machine to the clock in the host machine. Note that you must have VirtualBox Guest Additions installed in the virtual machine, so, if you have not already done that, do it first.
Issue the commands on the host machine. In the example commands shown below, the virtual machine name is ‘TestVM’. Obviously change the name in the command to whatever it is you have named your virtual machine. The grep
commands are simply to check that the required change to the .vbox
XML file has occurred.
The setextradata
command forces the virtual machine to get its time of day from the host machine by setting GetHostTimeDisabled
to zero (0 = enabled, 1 = disabled). The command stores the parameter in the .vbox
XML file of the virtual machine, ensuring that it is set every time the virtual machine boots.
The guestproperty
command forces the virtual machine to re-synchronise its clock to the host machine every ten seconds (ten thousand milliseconds). The command also stores the parameter in the .vbox
XML file of the virtual machine.
user $ VBoxManage setextradata "TestVM"
"VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 0
user $ grep GetHostTimeDisabled $HOME/VirtualBox-VMs/TestVM/TestVM.vbox
user $ VBoxManage guestproperty set "TestVM" "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold" 10000
user $ grep timesync $HOME/VirtualBox-VMs/TestVM/TestVM.vbox