old-www/HOWTO/Clock-3.html

191 lines
9.6 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
<TITLE>The Clock Mini-HOWTO: Software</TITLE>
<LINK HREF="Clock-4.html" REL=next>
<LINK HREF="Clock-2.html" REL=previous>
<LINK HREF="Clock.html#toc3" REL=contents>
</HEAD>
<BODY>
<A HREF="Clock-4.html">Next</A>
<A HREF="Clock-2.html">Previous</A>
<A HREF="Clock.html#toc3">Contents</A>
<HR>
<H2><A NAME="s3">3. Software</A></H2>
<H2><A NAME="ss3.1">3.1 Clock(8) and Hwclock(8)</A>
</H2>
<P>All linux distributions install either the old <CODE>clock(8)</CODE>
or the newer <CODE>hwclock(8)</CODE>, but without a correction
factor. Some may also install <CODE>adjtimex(8)</CODE>, or they may
include it on the CD as optional (or you can download it from
the usual Linux archive sites). Some distributions also include
a graphical clock setting program that runs in an X-window, but
those are designed for interactive use, and the system will still
install <CODE>clock(8)</CODE> or <CODE>hwclock(8)</CODE> for use in the
startup scripts.
<P><CODE>Clock(8)</CODE> requires you to calculate the correction factor
by hand, but <CODE>hwclock(8)</CODE> calculates it automatically
whenever you use it to reset the RTC (using another program to
set the RTC will interfere with the drift correction, so always
use the same program if you're using a correction factor). If you
have an older system that still uses <CODE>clock(8)</CODE> and you
want to upgrade, you can find <CODE>hwclock(8)</CODE> in the
&quot;<CODE>util-linux</CODE>&quot; package, version 2.7 or later.
See the man page for more information.
<P>
<DL>
<DT><B>Note</B><DD><P>The man page for <CODE>hwclock(8)</CODE> may be called
&quot;<CODE>clock</CODE>&quot; for backward compatibility, so
try both names. <CODE>Hwclock(8)</CODE> will respond to commands
written for <CODE>clock(8)</CODE>, but the result may not be the
same-- in particular, &quot;<CODE>hwclock -a</CODE>&quot; is
not quite the same as &quot;<CODE>clock -a</CODE>&quot;, so if
you're upgrading to <CODE>hwclock</CODE> I'd suggest replacing
all references to &quot;<CODE>clock</CODE>&quot; in your
startup scripts to use <CODE>hwclock</CODE>'s native commands
instead.
</DL>
<P>The startup scripts vary from one distribution to another, so you
may have to search a bit to find where it sets the clock. Typical
locations are <CODE>/etc/rc.local</CODE>,
<CODE>/etc/rc.d/rc.sysinit</CODE>,
<CODE>/etc/rc.d/boot</CODE>, or some
similar place.
<P>The correction factor for the RTC is stored in
<CODE>/etc/adjtime</CODE>.
Red Hat has a script in
<CODE>/etc/sysconfig/clock</CODE> that controls the
options to <CODE>hwclock</CODE>.
<P>When you're setting the clock to determine the drift rate, keep
in mind that your local telephone time announcement may or may
not be accurate. If you don't have a shortwave radio or GPS
receiver, you can hear the audio feed from WWV by calling
(303)499-7111 (this is a toll call to Boulder, Colorado). It
will cut you off after three minutes, but that should be long
enough to set the clock. USNO and Canada's CHU also have
telephone time services, but I prefer WWV's because there is
more time between the announcement and the &quot;beep&quot;.
You can also get the time from a network time server using the
<CODE>ntpdate</CODE> program that comes with <CODE>ntpd</CODE>, and
there's a javaclock at
<A HREF="www.time.gov">www.time.gov</A>.
<P>In any case, what you're setting is the system clock, not the RTC
(see the man page for the <CODE>date</CODE> command for the formats
to use). Then use <CODE>hwclock</CODE> to set the RTC and calculate
the drift rate. If you're doing this by hand, you should be able
to set it within a second or two, and get a reasonable
approximation of the drift rate after a few weeks. Then you can
run <CODE>adjtimex(8)</CODE> to fine-tune the system clock.
<H2><A NAME="ss3.2">3.2 Adjtimex(8)</A>
</H2>
<P><CODE>Adjtimex(8)</CODE> allows the user to adjust the kernel's time
variables, and therefore change the speed of the system clock
(you must be logged in as &quot;<B>root</B>&quot; to do
this). It is cleverly designed to compare the system clock to the
RTC using the same correction factor used by <CODE>clock(8)</CODE> or
<CODE>hwclock(8)</CODE>, as stored in <CODE>/etc/adjtime</CODE>.
So, once you've established the drift rate of the RTC, it's fairly simple
to correct the system clock as well. Once you've got it running
at the right speed, you can add a line to your startup scripts to
set the correct kernel variables at boot time. Since
<CODE>adjtimex(8)</CODE> was designed to work with <CODE>clock(8)</CODE>
or <CODE>hwclock(8)</CODE>, it includes a work-around for the
&quot;every 11 minutes&quot; bug.
<P>After you've installed <CODE>adjtimex(8)</CODE> you can get more
information on setting it up by typing &quot;<CODE>man 8
adjtimex</CODE>&quot; (there is also an <CODE>adjtimex(2)</CODE> man
page, which is not what you want) and by reading the
<CODE>README</CODE> file in <CODE>/usr/doc/adjtimex-1.3/README</CODE>
(where the version number in the path will be the current version
of <CODE>adjtimex(8)</CODE>).
<H2><A NAME="ss3.3">3.3 Xntpd and ntpd: the Network Time Protocol</A>
</H2>
<P><CODE>Xntpd</CODE> (NTPv3) has been replaced by <CODE>ntpd</CODE>
(NTPv4); the earlier version is no longer being maintained.
<P><CODE>Ntpd</CODE> is the standard program for synchronizing clocks
across a network, and it comes with a list of public time servers
you can connect to. It can be a little more complicated to set up
than the other programs described here, but if you're interested
in this kind of thing I highly recommend that you take a look at
it anyway.
<P>The &quot;home base&quot; for information on <CODE>ntpd</CODE>
is the NTP website at
<A HREF="http://www.eecis.udel.edu/~ntp/">http://www.eecis.udel.edu/~ntp/</A>
which also includes links to all kinds of interesting time-related
stuff (including software for other OS's). Some linux
distributions include <CODE>ntpd</CODE> on the CD. There is a list of
public time servers at
<A HREF="http://www.eecis.udel.edu/~mills/ntp/clock2.html">http://www.eecis.udel.edu/~mills/ntp/clock2.html</A>.
<P>A relatively new feature in <CODE>ntpd</CODE> is a &quot;burst mode&quot;
which is designed for machines that have only intermittent
dial-up access to the internet.
<P><CODE>Ntpd</CODE> includes drivers for quite a few radio clocks
(although some appear to be better supported than others). Most
radio clocks are designed for commercial use and cost thousands
of dollars, but there are some cheaper alternatives (discussed in
later sections). In the past most were WWV or WWVB receivers, but
now most of them seem to be GPS receivers. NIST has a PDF file
that lists manufacturers of radio clocks on their website at
<A HREF="http://www.boulder.nist.gov/timefreq/links.htm">http://www.boulder.nist.gov/timefreq/links.htm</A> (near
the bottom of the page). The NTP website also includes many links
to manufacturers of radio clocks at
<A HREF="http://www.eecis.udel.edu/~ntp/hardware.htm">http://www.eecis.udel.edu/~ntp/hardware.htm</A> and
<A HREF="http://www.eecis.udel.edu/~mills/ntp/refclock.htm">http://www.eecis.udel.edu/~mills/ntp/refclock.htm</A>.
Either list may or may not be up to date at any given time <CODE>:-)</CODE>.
The list of drivers for <CODE>ntpd</CODE> is at
<A HREF="http://www.eecis.udel.edu/~ntp/ntp_spool/html/refclock.htm">http://www.eecis.udel.edu/~ntp/ntp_spool/html/refclock.htm</A>.
<P><CODE>Ntpd</CODE> also includes drivers for several dial-up time
services. These are all long-distance (toll) calls, so be sure to
calculate the effect on your phone bill before using them.
<H2><A NAME="ss3.4">3.4 Chrony</A>
</H2>
<P><CODE>Xntpd</CODE> was originally written for machines that have a
full-time connection to a network time server or radio clock. In
theory it can also be used with machines that are only connected
intermittently, but Richard Curnow couldn't get it to work the
way he wanted it to, so he wrote &quot;<CODE>chrony</CODE>&quot; as an
alternative for those of us who only have network access when
we're dialed in to an ISP (this is the same problem that
<CODE>ntpd</CODE>'s new &quot;burst mode&quot; was designed to solve).
The current version of <CODE>chrony</CODE> includes drift correction
for the RTC, for machines that are turned off for long periods of
time.
<P>You can get more information from Richard Curnow's website at
<A HREF="http://www.rrbcurnow.freeuk.com/chrony">http://www.rrbcurnow.freeuk.com/chrony</A> or
<A HREF="http://go.to/chrony">http://go.to/chrony</A>.
There are also two <CODE>chrony</CODE> mailing lists, one for
announcements and one for discussion by users. For information
send email to
<CODE>
<A HREF="mailto:chrony-users-subscribe@egroups.com">chrony-users-subscribe@egroups.com</A></CODE>
or
<CODE>
<A HREF="mailto:chrony-announce-subscribe@egroups.com">chrony-announce-subscribe@egroups.com</A></CODE>
<P>Chrony is normally distributed as source code only, but Debian
has been including a binary in their &quot;unstable&quot;
collection. The source file is also available at the usual Linux
archive sites.
<H2><A NAME="ss3.5">3.5 Clockspeed</A>
</H2>
<P>Another option is the <CODE>clockspeed</CODE> program by DJ
Bernstein. It gets the time from a network time server and simply
resets the system clock every three seconds. It can also be used
to synchronize several machines on a LAN.
<P>I've sometimes had trouble reaching his website at
<A HREF="http://Cr.yp.to/clockspeed.html">http://Cr.yp.to/clockspeed.html</A>, so if you get a DNS
error try again on another day. I'll try to update this
section if I get some better information.
<HR>
<A HREF="Clock-4.html">Next</A>
<A HREF="Clock-2.html">Previous</A>
<A HREF="Clock.html#toc3">Contents</A>
</BODY>
</HTML>