Roots Discourse

Resetting Date/Time on Vagrant

Can anyone point me in the right direction to reset or resync the date and time on Vagrant?

From looking at this thread, it looks like that’s what I’m going to need to do, but I’m not sure the best way to do that, and the thread wasn’t very specific.

I can’t remember a specific incident, but there must have been a time recently where my computer went to sleep and the VM didn’t get suspended properly, and therefore the time and date got out of sync.

This is the error I’m getting when trying to run a vagrant provision command in Trellis:

Have you tried some of these options? https://www.google.com/search?q=vagrant+vm+set+time

I tried adding this command at the bottom of the Vagrantfile in the Trellis directory:

config.vm.provision :shell, :inline => "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime", run: "always"

That caused a syntax error when I tried to run vagrant provision.

I tried adding this to the end of the Vagrantfile in Trellis:

    Vagrant.configure("2") do |config|
  require 'time'
  offset = ((Time.zone_offset(Time.now.zone) / 60) / 60)
  timezone_suffix = offset >= 0 ? "+#{offset.to_s}" : "#{offset.to_s}"
  timezone = 'Etc/GMT' + timezone_suffix
  config.vm.provision :shell, :inline => "sudo rm /etc/localtime && sudo ln -s /usr/share/zoneinfo/" + timezone + " /etc/localtime", run: "always"
end

And I got the same “not yet valid” error.

I have another VM on my computer using Homestead, and I was able to do a vagrant provision on that site without issues, so something specifically must have happened to this Trellis site.

I ran these commands from this thread:

# Log in into the box
vagrant ssh

# VirtualBox syncs host time with guest, so we need to shut off VBox Guest Additions first
sudo service vboxadd-service stop

# Now you can set any date and time
sudo date -s "2020-05-04 10:25:00"

# Want to sync again with host? Restart Guest Additions
# Anyway on the next Vagrant up it will sync again regardless
sudo service vboxadd-service start

And I think I got it working. Or at least I was able to run vagrant provision without an error. But now I’m onto another bizarre issue, which I’ll start a new thread for. :slight_smile: