Nat Ritmeyer
Nat Ritmeyer

Reputation: 5678

How to disable VirtualBox time sync from within the guest at runtime

I have a VirtualBox VM running Centos 6.5 with Guest Additions installed and I need to be able to disable and enable time sync from within the guest at will. By default, the guest syncs its time with the host every 10 seconds[1], this is functionality built into the Guest Additions.

There are ways to disable the time sync but they are inadequate for my needs:

  1. Disable the time sync at VM startup:

    VBoxManage setextradata "VM name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1

  2. Disable the guest additions from within the VM at runtime:

    sudo service vboxadd-service stop

The reasons they don't work for me are:

  1. The first option only works at startup - I need to be able to do this at runtime
  2. The second option stops other functions that I need from the guest additions

When I run sudo VBoxControl guestproperty enumerate I don't see anything to do with time syncing.

So… a way to disable and enable time sync from within a VirtualBox VM without disabling the vboxadd-service service please :)

[1] https://www.virtualbox.org/manual/ch09.html#disabletimesync - Section 9.13.4

Upvotes: 22

Views: 53432

Answers (4)

Alexis Wilke
Alexis Wilke

Reputation: 20798

I tried the --disable-timesync solution, but on my VM it made no difference.

Note that in Ubuntu 18.04 the setup changed to partially make use of the systemd environment. The service is found in this file:

/lib/systemd/system/vboxadd-service.service

The ExecStart= line gives us the name of the script where the file is found:

/opt/VBoxGuestAdditions-6.1.20/init/vboxadd-service

You have to be careful as they reimplemented the daemon() and you can't just add a new option. You have to make sure all entries will know of that additional option.

The first one is here and you have to add $4:

daemon() {
    $1 $2 $3 $4
}

There is another definition where you also need to add $4 that looks like this:

daemon() {
    start-stop-daemon --start --exec $1 -- $2 $3 $4
}

Then you can add ONE option on the line like so:

    daemon $binary --disable-timesync --pidfile $PIDFILE > /dev/null

Without the previous two editing, it will fail.

Now, as I mentioned above, that didn't work for me. What I instead had to do is change the VM paravirtualization setup. By default it's set to Default which, I think, means KVM. Instead, I now use Minimal.

With the Minimal setup, now my VM keeps time properly with ntp. The Jitter is only around 4 or less. The offset is also very small. I kept the --disable-timesync because it shouldn't be necessary.

Upvotes: 0

Michael Giordano
Michael Giordano

Reputation: 11

I have a ubuntu/trusty64 virtual machine I built with vagrant. I had to turn off the time sync in the virtualbox guest addition on the virtual machine. To do this I added VBOX_OPTS to /etc/init.d/virtualbox-guest-utils like so:

edit /etc/init.d/virtualbox-guest-utils insert these lines:

if [ -n "$2" ]; then

 VBOX_OPTS="$VBOX_OPTS $2"

fi

modify this line:

start-stop-daemon --start --quiet --oknodo --exec /usr/sbin/VBoxService -- $VBOX_OPTS

Now stop and start the service like so

sudo service virtualbox-guest-utils stop
sudo service virtualbox-guest-utils start --disable-timesync

Now I can set the date to what I need and it stays that way until I reboot the machine.

date -s "2024-02-22 22:41:49,332" && date --rfc-3339=ns
date
Sat Feb 22 23:27:31 EST 2024

Upvotes: 1

Stefan Winkler
Stefan Winkler

Reputation: 3966

You should be able to edit the vboxadd-service script on the client and add the --disable-timesync option. Then sudo service vboxadd-service restart and time sync should be disabled.

See also https://www.winklerweb.net/index.php/blog/11-tools/25-disabling-time-synchronization-in-virtualbox-ubuntu-16-04

Upvotes: 8

bujon
bujon

Reputation: 323

This one worked for me: https://superuser.com/questions/742924/is-it-possible-to-get-a-virtualbox-vm-always-start-from-same-time-if-so-how

But I have windows guest and the change in registry was necessary to make it work. I don't know what is equivalent to windows registry settings in your guest CentOS system.

Upvotes: 1

Related Questions