1 TITLE: Using chrony to maintain system time
3 LFS VERSION: 3.1 (should apply to all)
5 AUTHOR: David Ayers <fogey@mindspring.com>
9 Chrony is a software package for maintaining the accuracy of computer
10 system clocks. It consists of a pair of programs: chronyd is a daemon
11 running in the background and chronyc is a command line control and
14 This hint describes the use of chrony to keep the system clock on a
15 single computer in step with NTP time over an Internet dial-up
16 connection. The chrony.txt file referenced below also describes how to
17 use chrony on systems with a full-time Internet connection or even no
28 chrony.txt located in the chrony-1.17 source tree provides very
29 complete documentation on the installation and use of chrony.
31 The man page for 'hwclock' tells how to query and set the hardware
37 LFS Version CVS-20020131
43 ftp://chrony.sunsite.dk/projects/chrony/chrony-1.18.tar.gz
45 Building and installing chrony
46 ------------------------------
48 Unpack the source code tarball, cd into the source directory and type:
50 $ ./configure --prefix=/usr
57 Choose your NTP server
58 ----------------------
60 The names and IP addresses for public NTP time servers, along with the
61 "Rules for Engagement" for their use, can be found at:
63 http://www.eecis.udel.edu/~mills/ntp/servers.htm
65 Unless you are configuring a computer for use as a time server for a
66 large network, choose your NTP servers from the list of secondary
67 (Stratum 2) servers. Because I live in Illinois, I chose two servers
68 located at the University of Illinois in Champaign, IL. You will need
69 both the name and IP of the server(s) you select.
74 Create the configuration file /etc/chrony.conf.
76 * # /etc/chrony.conf for LFS
77 * # Server names and IPs in /etc/hosts.
78 server [hostname] offline
79 server [hostname] offline
80 logdir /var/log/chrony
81 driftfile /etc/chrony.drift
82 keyfile /etc/chrony.keys
85 dumpdir /var/log/chrony
86 rtcfile /etc/chrony.rtc
88 Create a one-line keyfile /etc/chrony.keys. Pick an arbitrary
89 keyword. (The combination of a numeral and a keyword allows systems to
90 offer varying levels of access to users as explained in chrony.txt.)
94 Create the log directory and rtc file.
96 # mkdir /var/log/chrony/
97 # touch /etc/chrony.rtc
102 Add the IP address and host name of the NTP server or servers selected
103 to your /etc/hosts file. This is necessary for dial-up connections,
104 because DNS isn't available to resolve the server names until after
105 the online connection is established. Name resolution is provided
111 The start command for the chrony daemon is:
113 # /usr/bin/chronyd -r -s
115 The '-r' causes chronyd to reload the sample histories stored by the
116 'dumponexit' and 'dump' commands.
118 '-s' causes chronyd to set the system clock from the RTC. When used
119 with '-r' chronyd will attempt to preserve the old samples after
120 setting the system clock from the RTC. This allows chronyd to perform
121 long term averaging of the gain or loss rate across system reboots
122 and is useful for dial-up systems that are shut down when not in use
123 or when dual booting several OSs.
125 To start chrony on boot, create an appropriate boot script. I use the
126 'simple-init' boot system. My boot script:
131 # start chrony service
133 #locate and source functions script
134 source `PATH=$INIT_D/:/sbin/init.d:/etc/init.d:/etc/rc.d \
139 need $mounted_filesystems || exit_if_any_error
141 echo 'Starting chronyd daemon...'
142 loadproc chronyd -r -s || exit_if_any_error
145 echo 'Stopping chronyd daemon...'
155 Using the chronyc control and monitoring program
156 ------------------------------------------------
158 Type 'chronyc <command>' to monitor the operation of chronyd. The
159 monitoring commands are:
166 For help in interpreting the output of these commands, see chrony.txt.
168 Internet dial-up configuration
169 ------------------------------
171 The "offline" flag in chrony.conf prevents chronyd from trying to
172 query the time service when the computer is not connected to the
173 Internet. To switch to 'online' when connected, add these lines to
174 /etc/ppp/ip-up or whatever script takes you online:
176 /usr/bin/chronyc << EOF
181 To return to the offline state when disconnecting, add these lines to
182 /etc/ppp/ip-down (or equivalent script):
184 /usr/bin/chronyc << EOF
194 One of the main activities of the 'chronyd' program is to work out the
195 rate at which the system clock gains or loses relative to real
196 time. Every time this rate information is computed, it is recorded in
197 the driftfile /etc/chrony.drift. Data in the driftfile looks
200 $ cat /etc/chrony.drift
203 The first number is the rate at which the system clock gains or loses
204 time in parts-per-million. The second rate is an estimate of the error
205 bound around the first value in which the true rate actually lies.
207 Synchronizing the hardware clock (RTC)
208 --------------------------------------
210 The computer relies on the real-time clock (RTC) to maintain the
211 correct time during shutdown and offline periods. At boot up, chronyd
212 sets the system time to RTC time. When the Internet connection is
213 made, chronyd starts measuring the error and drift rate between system
214 and RTC time, gradually bring both times into sync with the NTP
215 time signal. After a number of hours online, both system time and RTC time
216 will equal true time.
218 My LFS system used a 'setclock' boot script to set system time to the
219 resl-time clock. Since chronyd now fulfills this function, I removed
220 'setclock' from the boot process. Any program other than chronyd that
221 adjusts the real-time clock can confuse the time synchronization