启动时自动更新 hwclock

启动时自动更新 hwclock

我们的 Beagle Bone Black 遇到了一个小问题。由于它们没有配备 RTC 电池,因此当它们断电时,硬件时钟就会变得混乱。我需要一种简单而干净的方法来在启动时将 hwclock 同步到系统时钟。系统时钟当然是从 ntpd 获取时间的,因此启动后,系统时钟是完美的。我正在寻找解决方案,只需要一些建议和一点语法。

我想并尝试添加:

/sbin/hwclock --systohc

到 /etc/init.d/ntp (在启动案例的内部和末尾),起初这似乎有效,但现在经过几次测试后,它不再工作了。我不确定发生了什么变化。也许我只是认为它有效。

我知道 hwclock -w 效果很好,我知道我可以做一些事情,比如将它放入启动时的 cron 作业中,但如果可以的话,我更喜欢避免 cron。还有其他建议或语法更改吗?

谢谢

顺便说一句,这是在 Debian 上,但我们也需要它在 Ubuntu 上工作。

答案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。这意味着您可以拥有一个稍微正确的时钟,以防启动时出现网络问题。

相关内容