You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VirtualBox+Vagrant+Homestead休眠唤醒后时间不同步解决方案咨询

Fixing Homestead Time Desync After Host Sleep/Wakeup

I’ve run into this exact frustrating issue with older Vagrant/VirtualBox setups before—destroying and recreating the box every time is such a waste of time. Let’s walk through reliable fixes tailored to your setup (Homestead 5.0.1, Vagrant 2.0.1, VirtualBox 5.2.4):

1. Enhance Vagrantfile Config for Automatic Sync

Your current config has some pieces, but we can beef it up to force time sync on wakeup and make the sync trigger more sensitively. Update your Vagrantfile with these additions:

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # Keep your existing config here...
  
  config.vm.provider 'virtualbox' do |vb|
    # Lower the sync threshold to 1 second (triggers sync if time differs by >1s)
    vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 1000 ]
    # Explicitly enable the time sync service
    vb.customize [ "guestproperty", "set", :id, "/VirtualBox/GuestAdd/VBoxService/--timesync-enable", "1" ]
    # Keep your existing network cable setting
    vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
  end

  # Add a systemd service to force sync when the VM wakes from sleep
  config.vm.provision "shell", inline: <<-SHELL
    # Ensure VBoxService runs on boot
    systemctl enable vboxservice
    # Create a wakeup-triggered sync service
    cat > /etc/systemd/system/homestead-time-sync.service <<EOF
    [Unit]
    Description=Force time sync when Homestead wakes from sleep
    After=suspend.target hibernate.target hybrid-sleep.target

    [Service]
    Type=oneshot
    ExecStart=/usr/sbin/VBoxControl timesync force

    [Install]
    WantedBy=suspend.target hibernate.target hybrid-sleep.target
    EOF
    # Enable the service
    systemctl enable homestead-time-sync.service
  SHELL

  # Rest of your config...
end

After updating, run vagrant reload --provision to apply the changes. This setup does two key things:

  • Makes time sync trigger more often (when time differs by over 1 second instead of 10)
  • Adds a systemd service that automatically runs a forced time sync whenever the VM wakes up from sleep/hibernation.

2. Quick Manual Fix (For Immediate Relief)

If you don’t want to reconfigure right now, just SSH into your Homestead box (vagrant ssh) and run this command to force an immediate time sync:

sudo VBoxControl timesync force

This will sync the VM's time to your host's without needing to destroy and restart the box.

3. Verify Guest Additions Compatibility

Time sync issues often crop up when VirtualBox Guest Additions inside the VM don’t match your host’s VirtualBox version. Since you’re on VirtualBox 5.2.4, double-check that the Guest Additions in your Homestead box are also 5.2.4. If not, you can update them via the VirtualBox menu (Devices > Insert Guest Additions CD Image) or use a Vagrant plugin like vagrant-vbguest to automate updates.

Also, if you can spare the time, upgrading to newer stable versions of Vagrant (2.2.x+) and VirtualBox (6.x+) might resolve the underlying sleep/wake sync bug entirely—older versions had known issues with this.

内容的提问来源于stack exchange,提问作者Fredrik

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 03:31:24