What's the easiest way to make Busybox keep correct time?

Isaac Dunham ibid.ag at gmail.com
Tue Sep 2 17:01:33 UTC 2014


On Tue, Sep 02, 2014 at 06:23:50PM +0200, Harald Becker wrote:
> Hi Denys!
> 
> On 02.09.2014 15:52, Denys Vlasenko wrote:
> >$ busybox ntpd --help
> >BusyBox v1.22.1 (2014-02-01 19:25:19 CET) multi-call binary.
> >
> >Usage: ntpd [-dnqNwl] [-S PROG] [-p PEER]...
> >
> >NTP client/server
> >
> >     -d    Verbose
> >     -n    Do not daemonize
> >     -q    Quit after clock is set
> >     -N    Run at high priority
> >     -w    Do not set time (only query peers), implies -n
> >     -l    Run as server on port 123
> >     -p PEER    Obtain time from PEER (may be repeated)
> >     -S PROG    Run PROG after stepping time, stratum change, and every 11 mins
> >^^^^^^^^^^^^^^^^^^
> >     use this to periodically set the hw clock
> 
> What about this (from hwclock manpage)?
> 
> Automatic Hardware Clock Synchronization By the Kernel
> 
> You should be aware of another way that the Hardware Clock is kept
> synchronized in some systems. The Linux kernel has a mode wherein it copies
> the System Time to the Hardware Clock every 11 minutes. This is a good mode
> to use when you are using something sophisticated like ntp to keep your
> System Time synchronized. (ntp is a way to keep your System Time
> synchronized either to a time server somewhere on the network or to a radio
> clock hooked up to your system. See RFC 1305).
> 
> This mode (we'll call it "11 minute mode") is off until something turns it
> on. The ntp daemon xntpd is one thing that turns it on. You can turn it off
> by running anything, including hwclock --hctosys, that sets the System Time
> the old fashioned way.
> 
> To see if it is on or off, use the command adjtimex --print and look at the
> value of "status". If the "64" bit of this number (expressed in binary)
> equal to 0, 11 minute mode is on. Otherwise, it is off.
> 
> If your system runs with 11 minute mode on, don't use hwclock --adjust or
> hwclock --hctosys. You'll just make a mess. It is acceptable to use a
> hwclock --hctosys at startup time to get a reasonable System Time until your
> system is able to set the System Time from the external source and start 11
> minute mode.
> 
> 
> The question is: Does Busybox ntpd activate this 11 minute mode?

Per adjtimex, eventually it does.
(Note: it seems that "busybox adjtimex" is equivalent to "adjtimex --print".)
$ adjtimex
    mode:         0
-o  offset:       -435
-f  frequency:    6028
    maxerror:     16000000
    esterror:     16000000
    status:       1 (PLL)
-p  timeconstant: 5
    precision:    1
    tolerance:    32768000
-t  tick:         10000
    time.tv_sec:  1409676091
    time.tv_usec: 818519
    return value: 0 (clock synchronized)

(I'd started "service ntpd" on Alpine about a minute beforehand.
That's Busybox ntpd.)

HTH,
Isaac Dunham


More information about the busybox mailing list