r/linuxadmin • u/grievre • Mar 12 '26
Power-on time sync on an isolated network where RTC may or may not work.
I know this is an extreme edge case, but I have a "box" which contains:
- Five Linux machines
- of which two have an RTC with a battery backup that might work
- that may or may not have a connection to the internet at any given time.
If I only had a single RTC this would be much simpler, but basically what I'm looking for is a way that, when this whole thing is powered on, all five can synchronize time, with ideally no steps backwards, before it has an internet connection.
The tricky part here is how to handle the case when one of the two battery backed RTCs dies. There's no "later time wins" option that I can see in chrony or any other ntp solution.
3
Upvotes
4
u/Markohs Mar 12 '26 edited Mar 12 '26
Installing systemd-timesyncd, or ntp should solve all this problems, no?
A other option is installing ntpd on one of the servers, specially one with RTC, and have the rest of the machines sync to this one. If time difference gets too big on boot on the non RTC machines you can force sync via a script in startup using 'ntpdate' and the IP or your time source server
2
u/Unreal_Estate Mar 12 '26
If all you care about is still having a functioning time system when either one of the battery backups fails, then all you need to do for those two systems is to install an NTP client that starts only on the condition that the clock has gone backwards (probably to a predictable date, even).
That means that when both clocks are good, you will have the correct time with two sources of truth, and when only one good clock remains, then you will still have the correct time, just from only one source.
But, there are other - better - options as well. Probably the most straight forward option is to add some sort of GPS module to to your box. GPS is an extremely accurate time source, and it doesn't depend on network connectivity. This could be an old phone, a USB or bluetooth GPS module, or a raspberry pi with a GPS hat.
2
u/michaelpaoli Mar 12 '26
NTP. Just don't have NTP fire up if they have no reasonable time source (e.g no RTC available, or no readonably well synced NTP available). Then what's lacking RTC can use NTP early in the boot process. That's pretty much it - so long as you've always got a local NTP server operating with reasonable time, you're in pretty good shape, though host with missing/failed RTC may not have good system time without that until it fist talks to decent NTP source. To minimize impacts in such cases, may want to push using NTP as client to set time as early n the boot as feasible, e.g. like within the initrd, before the true root filesystem is mounted (pivotroot) in its proper place.
2
u/whetu Mar 12 '26
Two time sources is essentially the worst NTP config. The best practice is a pool, or if using specific servers: 1 or >=4. There's plenty of discussion about this elsewhere, like this thread in /r/sysadmin:
https://www.reddit.com/r/sysadmin/comments/bo1xvh/how_many_ntp_server_should_we_have/
What I would do in your situation is either:
Either way, if your one authoritative source dies, what matters is that the rest of them drift roughly in unison until you restore your time source. With that in mind, the second option is probably best for your specific situation: If there's no authoritative source, then the rest of the hosts can bang their heads together such that they do drift together.
4
u/weregeek Mar 12 '26 edited Mar 12 '26
It's not clear what your budget or accuracy requirements are. One option would be to pick up a GPS NTP appliance. If that's not within your budget, and sub-millisecond accuracy isn't essential, then you could likely use a USB GPS dongle attached to one of your existing machines. Both of these options assume that you can place an antenna in a position to get a GPS signal.
1
u/fubes2000 Mar 12 '26
I think you're misinterpreting the advice here:
The real question is: Does it matter if the site has reliable time compared to the outside world, or only that these 5 servers are in sync?