如何设置流浪环境的日期和时间?
我试图在流浪环境(例如6月29日)设置日期和时间。
我使用以下vagrantfile来实现这一目标。
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.provider "virtualbox" do |vb|
end
config.vm.provision :shell, :inline => "sudo date -s '2022-06-29 12:34:56'", run: "always"
end
当我运行Vagrant Up
时,我会看到
[...] 默认值:运行:内联脚本
默认值:6月29日星期三12:34:56 UTC 2022
但是当我与SSH连接并执行日期
时,当前日期已打印。
当我尝试通过sudo日期手动更改时间时-s'2022-06-29 12:34:56'
并执行我看到了更改的日期。
但是,如果我退出并重新进入,我再次看到当前日期和时间。
我如何在环境上永久更改日期和时间,或者至少在环境启动时将其设置?
注意:这个答案描述了如何在VirtualBox-Level上执行此操作:
VBoxManage setextradata "The VM name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
# Milliseconds to shift to in the past
VBoxManage modifyvm "The VM name" --biossystemtimeoffset -50000000
我测试了上述操作,显然可以计算出知道当前日期和日期的毫秒我们想去。但是同样,以上不是Vagrant的自动解决方案。
I am trying to set the date and time on a vagrant environment (e.g. to 29th of June).
I used the following Vagrantfile to achieve this.
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/focal64"
config.vm.provider "virtualbox" do |vb|
end
config.vm.provision :shell, :inline => "sudo date -s '2022-06-29 12:34:56'", run: "always"
end
When I run vagrant up
I see
[...]
default: Running: inline script
default: Wed Jun 29 12:34:56 UTC 2022
but then when I connect with ssh and execute date
the current date is printed.
When I try to change the time manually via ssh with sudo date -s '2022-06-29 12:34:56'
and execute date
I see the changed date.
But If I exit and get back in, I again see the current date and time.
How can I permanently change the date and time on an environment, or at least set it when the environment starts?
NOTE: This answer describes how to do this on virtualbox-level:
VBoxManage setextradata "The VM name" "VBoxInternal/Devices/VMMDev/0/Config/GetHostTimeDisabled" 1
# Milliseconds to shift to in the past
VBoxManage modifyvm "The VM name" --biossystemtimeoffset -50000000
I tested the above and it works and obviously the milliseconds can be calculated knowing the current date and the date to which we want to go to. But again the above is not an automatic solution via Vagrant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法使用触发器找到了部分虚拟盒特定的解决方案:
我想剩下的就是根据当前VM的日期计算毫秒以转移到所需日期的毫秒。
I managed to find a partial virtualbox-specific solution using triggers:
I guess what is left is to calculate the milliseconds for shifting to the desired date based on current vm's date.