Ubuntu力量日期和时间,如果NTP可以更新
我在Raspberry Pi 4上运行Ubuntu 20.04。由于它没有RTC,因此除非在网络上并可以到达NTP服务器,否则日期/时间无法更新。
有时,该系统会在网络上启动到可以进入NTP服务器的网络,但有时会启动并与网络断开并断开连接,或者在没有NTP服务器的封闭网络上。
有没有一种方法可以手动 force 当前日期和时间,但是保持NTP活动性,因此,如果下次启动系统时,如果它可以到达NTP服务器,它将同步?如果我尝试使用NTP Active设置时间(使用timeDatectl
),我会得到错误:
Failed to set time: Automatic time synchronization is enabled
如果关闭NTP,我可以设置时间,但是一旦我重新启用NTP,重置上次同步的时间,失去了我刚刚设定的时间。
有什么办法解决的吗?保持NTP的活动状态(即使通过IT 当前也无法进入服务器),但手动使系统更准确地日期/时间?
更新
我认为我发现文件NTP正在使用该文件启动的日期/时间。看起来它是从/var/lib/systemd/timessync/clock
中拉出的。如果关闭NTP,请设置我想要的日期/时间,touch
此文件,然后重新启动NTP,它可以保留我设置的时间。
这是完成我想要的最佳方法吗?
I am running Ubuntu 20.04 on a Raspberry Pi 4. Since it doesn't have a RTC, the date/time can't update unless it is on the network and can get to an NTP server.
Sometimes this system is booted up on a network where it can get to an NTP server, but sometimes it is booted up and disconnected from a network, or on a closed network with no NTP servers.
Is there a way to manually force the current date and time, but keep NTP active so if next time the system is booted it will sync if it can get to an NTP server? If I try to set the time (using timedatectl
) with NTP active I get the error:
Failed to set time: Automatic time synchronization is enabled
If I turn off NTP, I can set the time, but as soon as I re-enable NTP it seems to reset the time to when it was last synced, losing the time I just set.
Is there any way around this? Keep NTP active (even through it currently can't get to a server) but manually give the system a more accurate date/time?
UPDATE
I think I found the file NTP is using to get the date/time when it is started. It looks like it pulls this from /var/lib/systemd/timesync/clock
. If I turn off NTP, set the date/time I want, touch
this file, and then restart NTP, it keeps the time I set.
Is this the best way to accomplish what I want?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果要同步日期:
从此
Try this script (or standalone command) if you want to synchronize the date:
Taken from this link