Dr. Stefan Winkler
freier Softwareentwickler und IT-Berater

NOTE! This site uses cookies to track your user session.

If you not change browser settings to prevent accepting cookies, you agree to it.

I understand

Sometimes I need to test something in a VM which has an independent system time. Usually, this has to do with server applications which react time-based (think of a system in which users may enter information until a certain day is reached, after which only read-only is allowed). 

On a standard installation of VirtualBox and Ubuntu 16.04, the system time is automatically synced to the host. When trying to change the date using date -s 2015-01-01 the date will be updated but will revert to the host's date after a few seconds.

Since I end up googling the correct way to disable the time synchronization in an Ubuntu VirtualBox client every time I set up my VM from scratch, I am posting the steps here as my personal reminder (it is always nice to get one's own article in a google result because one has forgotten ;)) - and maybe someone else also finds this useful:

  1. Disable host time access (this is mentioned here - no idea if this is really required...):
    On the host, execute: 
    VBoxManage setextradata "vm-name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
  2. Disable client time sync:
    On the client, edit /opt/VBoxGuestAdditions-5.1.2/init/vboxadd-service  and in start() replace
    daemon $binary --pidfile $PIDFILE > /dev/null
    with
    daemon $binary --disable-timesync --pidfile $PIDFILE > /dev/null

    and also look for the definition of daemon() and add the fourth argument
    if which start-stop-daemon >/dev/null 2>&1; then
      daemon() {
        start-stop-daemon --start --exec $1 -- $2 $3 $4
      }
    ...
  3. Just to be sure, remove the Ubuntu timesyncd as well:
    On the client, execute:
    rm /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service

Reboot and from now on, changed system dates stay as intended.

BTW, I would like to be able to decouple the system time in docker as well, but from my understanding this is not possible because docker uses the host RTC directly and the only way to differ here is to set a different timezone, which has its limitations. But if someone knows a way to simulate a different system time in docker, I would love to hear about it!

{jcomments on}