Using NTP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello again:

The environment variable TZUTC provides the complement to
/etc/localtime in making a linux system leap-second-aware.  This email
is a sort of mini-howto for configuring a recent linux kernel to fully
use NTP with a hwclock that understands TZUTC (is leap-second-aware).

I have assumed here that the RTC is kept in UTC, that leap-second-aware
zonefiles are found in /usr/share/zoneinfo/right, that you have set
/etc/localtime to point to the correct leap-second-aware zonefile for
your timezone, and that you are using a recent glibc.  Make appropriate
corrections if you use other conventions.

Even if no RTC driver is installed and the /dev/rtc device does not
exist, the linux kernel will initialize its system time to whatever is
in a standard RTC converted under the assumption that the RTC contains
POSIX UTC.  That is, like hwclock, the kernel knows how to directly
access standard RTC hardware.

You will need to do the following additional things in the following
order in system startup scripts:

1.  Reset the POSIX system time, which the kernel has set from the RTC
automatically at startup, to NTP time which is currently 25 seconds
greater (the number of leap seconds).  For example:

    TZUTC=:/usr/share/zoneinfo/right/UTC \
    hwclock --hctosys --utc --noadjfile

Do this as early as possible while the root filesystem is still mounted
readonly and before any attempt is made to use the system time (like
filesystem checks).  This example assumes that you have a PC with
standard RTC hardware.

It should also work if your system uses a non-standard RTC.  However,
then the appropriate RTC driver must be loaded first or built into the
kernel.  You must also specify /dev/rtc<N> on the hwclock command line
above with the additional option --rtc=/dev/rtc<N>.  Instead, you may
specify /dev/rtc<N> in the filesystem and link /dev/rtc to it, in which
case you do not need to add the --rtc option to the command line above. See the kernel documentation rtc.txt and hwclock.8 for more
information.

Note that you do not need to load the rtc-cmos module on a PC with
standard RTC hardware unless you want the additional features it
provides.  The kernel will provide legacy access to standard RTC
hardware without an additional driver.  If you do load rtc-cmos, then
you should treat your RTC as non-standard; that is you will also need
to specify /dev/rtc<N> (/dev/rtc0 by default) or link /dev/rtc as
above.


2.  Start ntpd.  For example:

    ntpd -g -I eth1

Do this much later after the interface that NTP will use and the name
server have been brought up.  Prior to this step, the system clock is
running close to NTP time from the RTC, though not yet locked on to an
NTP client.  Because it is close, operations performed during this period
have very close timestamps and ntpd can quickly bring the system clock
into sync.


3.  Set the RTC to the NTP system time.  Even if the system time has
not yet been changed by ntpd, and this operation has little or no
effect on the RTC, you are telling the kernel not to touch the RTC in
the future.  The RTC will be maintained in sync from user space by a
cron job (see 4 below).  For example:

    hwclock --systohc --utc --noadjfile

Do this right after step 2.


4.  Start a cron job which does the same thing every hour.  For
example:

    hwclock --systohc --utc --noadjfile


You may want to do other hwclock operations on startup and shutdown
that maintain and use /etc/adjtime.  This is useful if your system is
powered down for long periods where RTC drift is substantial.  But if
your system is running on a UPS and is only down for short periods,
this will not be necessary.

Do not hesitate to email me with questions, suggestions, gripes, money,
etc.


Hope this helps.  Regards,

Joseph Parmelee
jparmele at wildbear dot com
--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux