How to sync time on host wake-up within VirtualBox?

后端 未结 6 1488
独厮守ぢ
独厮守ぢ 2020-12-23 09:22

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. T

相关标签:
6条回答
  • 2020-12-23 09:36

    I found a solution:

    1. install ntpdate
    2. add "s" permission for ntpdate, this allows non-root users to run ntpdate as root: sudo chmod u+s /usr/sbin/ntpdate
    3. add one line in ~/.bashrc: ntpdate -u ntp.ubuntu.com

    After that, each time you login to the linux system, the time will be sync once.

    0 讨论(0)
  • 2020-12-23 09:40

    I give an other solution to sync time between guest & host without installing Virtualbox guest addition:

    1. install ntp on your guest, and de-comment these lines in /etc/ntp.conf:

      disable auth
      broadcastclient
      

    Then, restart ntp with service ntp restart

    1. Active broadcast on your host:

      • For Linux users, edit your /etc/ntp.conf file and configure broadcast (you must adapt IP):

        broadcast 192.168.123.255

      • For Windows users, activate the "Windows Time" service. You can then read this page to configure it to broadcast time

      Then, restart time service on host.

    0 讨论(0)
  • 2020-12-23 09:41

    Summarizing answers of @zilupe and @Slobodan Kovacevic, solution is to add following to Vagrantfile:

    config.vm.provider 'virtualbox' do |vb|
       vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000 ]
    end
    

    This will synchronize clocks each time when desync becomes > 1s (1000ms)

    0 讨论(0)
  • 2020-12-23 09:48

    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
    
    0 讨论(0)
  • 2020-12-23 09:52

    For me to get timesync working I had to do this:

    vboxmanage setextradata «machine-name» "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 0

    It turns the timesync on. It was, for some reason, off.

    0 讨论(0)
  • 2020-12-23 09:54

    you can install the VirtualBox Guest Additions in the VM to sync the time automatically by VB.

    0 讨论(0)
提交回复
热议问题