I'm working with a setup that's a bit unique: I have five Linux machines, two of which are equipped with a battery-backed real-time clock (RTC) that may or may not function properly. The challenge is that these machines might not have an internet connection when they start up. I'm looking for a reliable way to ensure that when I power on all five machines, they can synchronize their time without having to revert to an incorrect time, especially if one of the RTCs fails. I know that having just one RTC would make this straightforward, but the two that I have could also fail, making time synchronization a tricky issue. What are the best strategies or tools to achieve this under these conditions?
5 Answers
If your budget allows, you could consider a GPS NTP appliance for accurate time. If it's too high-priced, a USB GPS dongle might work as an alternative; just ensure you have an antenna set up to catch GPS signals. This gives you a reliable time source without needing internet access.
The trick is to manage NTP settings properly. You could avoid starting NTP if there's no reliable time source available. This way, systems with non-functional RTCs can start syncing as soon as possible once they're able to interact with an NTP server. Setting NTP to adjust time early in the boot process can help mitigate issues with incorrect timestamps until they connect to a solid time source.
Having two RTCs can complicate NTP configurations since having just two sources can lead to inconsistent time syncing. One option is to designate one as the main authority, or set up a peer-to-peer system where all machines sync with each other. This way, even if one source fails, the rest can maintain synchronized time until the issue is resolved.
Using `systemd-timesyncd` or NTP might just solve your problems. One approach is to install `ntpd` on one of the machines with an RTC and have the others sync to it. If the time difference is too large on boot, you could start a script that forces a sync using `ntpdate`. This way, you maintain a valid time even if the connection is unreliable.
To keep time functioning even when one RTC fails, you can set up an NTP client that only activates if it detects the time has gone backwards. This way, with both clocks working, you'll have two time sources, but if one dies, at least one will still be accurate. Adding a GPS module is also a good idea, as GPS provides precise time without relying on network connectivity.

How would that work exactly? Can you elaborate on how these options would handle syncing when the system is powered on?