0

I have an embedded Linux system without RTC, so it (currently) boots with thinking it's Jan, 1st 1970.

I have ntpd installed and started as:

/usr/bin/ntpd -g

with a pretty standard /etc/ntp.conf:

server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
server 3.pool.ntp.org iburst

restrict default nomodify nopeer noquery limited kod
restrict 127.0.0.1
restrict [::1]

Unfortunately this takes a looong time (sometimes >120s) to achieve lock (i.e.: a peer flagged with * in ntpq -nc peers).

What further options (if any) could I use to shorten as much as possible sync time?

Related question: what is a reasonable sync time (assuming a reasonable network connection with ~16ms ping time to 0.pool.ntp.org)?

Note: I did read man 8 ntpd and man 5 ntp.conf, but I'm pretty confused and I would like expert advice.

Update:

Given the comments I think I need to elaborate my use-case:

  1. My embedded Linux system does not have a RTC, so it wakes up at Jan 1st 1970.
  2. I start ntpd from sysV initialization scripts as start-stop-daemon -S -q -x /usr/sbin/ntpd -- -g
  3. I need to know when system time is "reasonably close" (I can accept error of several seconds, not in the "minutes" range).
  4. Network may be either wired or WiFi (or both), so it may take a substantial amount of time for it to get up.
  5. Even when LAN is up-and-running I may have problems accessing Time Servers due to connectivity, NAT or firewalling; this means waiting a fixed amount of time won't work (even if I can ping the server!).
  6. I can have "correct" time by means different from ntp (e.g.: user explicitly sets date&time, possibly with huge error!).

My aim is to get info, as soon as possible, if current time was retrieved from ntp server (so it can be "trusted") or not. As said I do not need sub-second precision, but I need to know "for sure" if and when minute is correct, as soon as possible, assuming net is working, of course).

9
  • Did you consider to use ntp pool near to you? server 0.it.pool.ntp.org – Romeo Ninov Dec 13 '19 at 12:59
  • @RomeoNinov Generally, using the main pool should automatically select servers close by. – Kusalananda Dec 13 '19 at 13:06
  • Have you try to run ntpdate at startup of the system to force time sync? – Romeo Ninov Dec 13 '19 at 13:09
  • @RomeoNinov: I could do that, but I sincerely doubt I'll get a faster ping time over a WiFi / NATted connection. I tested on a live system: ping times are very similar (and randomly changing due to pool selection). I'm looking for a more stable solution. – ZioByte Dec 13 '19 at 13:09
  • 1
    @Kusalananda: I seem unable to explain myself :( Please let me rephrase: after I issue a start-stop-daemon -S -q -x /usr/sbin/ntpd -- -g (which returns immediately) how can I detect ntpd is "reasonably sure" it has the correct time? what can/should I poll? Obviously waiting a fixed amount of time is not enough (e.g.: net could be down). – ZioByte Dec 13 '19 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.