NTP:不使用 hwclock,定期保存时间以供下次重启

NTP:不使用 hwclock,定期保存时间以供下次重启

我在没有硬件时钟的 ARM 板上运行 ntpd(因此关闭时无法保持时间)。

问题是,重新启动后,时间始终设置为 unix 纪元,直到 ntpd 能够再次同步。

我希望 ntpd 定期将当前时间保存到文件中,并在下次系统启动时重新应用它。虽然它不准确,但至少它不会在每次重启时将我带回到 unix 纪元。

不一定非得是 ntpd,也许其他软件(甚至是内核端?)可以做到这一点?

最坏的情况是我总是可以让 init.d 脚本执行此操作,但我认为这已经在某个地方以适当的方式实现了。

答案1

安装fake-hwclock程序:

# apt-get install fake-hwclock


fake-hwclock: Save/restore system clock on machines without working RTC hardware

 Some machines don't have a working realtime clock (RTC) unit, or no
 driver for the hardware that does exist. fake-hwclock is a simple set
 of scripts to save the kernel's current clock periodically (including
 at shutdown) and restore it at boot so that the system clock keeps at
 least close to realtime. This will stop some of the problems that may
 be caused by a system believing it has travelled in time back to
 1970, such as needing to perform filesystem checks at every boot.

 On top of this, use of NTP is still recommended to deal with the fake
 clock "drifting" while the hardware is halted or rebooting.

安装 fake-hwclock 后,您的机器不会在启动时误以为时间又回到了 1970 年。当您的机器启动时,它会将其时钟设置为 fake-hwclock 在上次重启/关机时写入的时间戳。这意味着,如果您在启动时出现网络问题,您可以获得一个相对正确的时钟。

相关内容