]> git.ipfire.org Git - thirdparty/util-linux.git/blame - sys-utils/hwclock.8.in
hwclock: remove depreciated ntpdate
[thirdparty/util-linux.git] / sys-utils / hwclock.8.in
CommitLineData
2ed1d701
J
1.\" hwclock.8.in -- man page for util-linux' hwclock
2.\"
3.\" 2015-01-07 J William Piggott
4.\" Authored new section: DATE-TIME CONFIGURATION.
5.\" Subsections: Keeping Time..., LOCAL vs UTC, POSIX vs 'RIGHT'.
6.\" Errata and drop outdated language.
7.\" Updates for v2.26
8.\"
9.\"
10.\" -------------------------------
11.\" Included for troff portability.
12.\" Continuation line for .TP header.
13.de TQ
14. br
15. ns
16. TP \\$1\" no doublequotes around argument!
17..
18.
19.\" -------------------------------
20.
21.TH HWCLOCK 8 "January 2015" "util-linux" "System Administration"
fd6b7a7f 22.SH NAME
2ed1d701 23hwclock \- read or set the hardware clock (RTC)
fd6b7a7f 24.SH SYNOPSIS
93f9a8e4 25.B hwclock
5474e57f
BS
26.RI [ function ]
27.RI [ option ...]
2ed1d701 28.
fd6b7a7f 29.SH DESCRIPTION
66ee8158 30.B hwclock
2ed1d701
J
31is a tool for accessing the Hardware Clock. It can: display the
32Hardware Clock time; set the Hardware Clock to a specified time; set the
33Hardware Clock from the System Clock; set the System Clock from the
34Hardware Clock; compensate for Hardware Clock drift; correct the System
35Clock timescale; set the kernel's timezone, NTP timescale, and epoch
36(Alpha only); compare the System and Hardware Clocks; and predict future
37Hardware Clock values based on its drift rate.
fd6b7a7f 38.PP
cb15645b
J
39Since v2.26 important changes were made to the
40.B \-\-hctosys
1afe0412
WP
41function, the
42.B \-\-directisa
43option, and a new option
cb15645b
J
44.B \-\-update\-drift
45was added. See their respective sections below.
2ed1d701 46.
28e984a4 47.SH FUNCTIONS
2ed1d701
J
48The following functions are mutually exclusive, only one can be given at
49a time. If none are given the default is
50.BR \-\-show .
ae4cc2ad
BS
51.TP
52.B \-\-adjust
53Add or subtract time from the Hardware Clock to account for systematic
54drift since the last time the clock was set or adjusted. See the
2ed1d701
J
55discussion below, under
56.BR "The Adjust Function" .
57.
ae4cc2ad
BS
58.TP
59.BR \-c , \ \-\-compare
60Periodically compare the Hardware Clock to the System Time and output
61the difference every 10 seconds. This will also print the frequency
62offset and tick.
2ed1d701 63.
ae4cc2ad
BS
64.TP
65.B \-\-getepoch
2ed1d701
J
66.TQ
67.B \-\-setepoch
68These functions are for Alpha machines only.
69.sp
70Read and set the kernel's Hardware Clock epoch value.
71Epoch is the number of years into AD to which a zero year value in the
ae4cc2ad
BS
72Hardware Clock refers. For example, if you are using the convention
73that the year counter in your Hardware Clock contains the number of
74full years since 1952, then the kernel's Hardware Clock epoch value
75must be 1952.
fc56c363 76.sp
2ed1d701
J
77The set function requires using the
78.B \%\-\-epoch
79option.
80.sp
ae4cc2ad 81This epoch value is used whenever
2ed1d701 82.B \%hwclock
ae4cc2ad 83reads or sets the Hardware Clock.
2ed1d701 84.
ae4cc2ad 85.TP
2ed1d701
J
86.B \-\-predict
87Predict what the Hardware Clock will read in the future based upon the
88time given by the
ae4cc2ad 89.B \-\-date
2ed1d701
J
90option and the information in
91.IR @ADJTIME_PATH@ .
92This is useful, for example, to account for drift when setting a
93Hardware Clock wakeup (aka alarm). See
94.BR \%rtcwake (8).
95.sp
96Do not use this function if the Hardware Clock is being modified by
97anything other than the current operating system's
98.B \%hwclock
99command, such as \%'11\ minute\ mode' or from dual-booting another OS.
100.
fd6b7a7f 101.TP
93f9a8e4 102.BR \-r , \ \-\-show
2ed1d701
J
103.TQ
104.B \-\-get
105.br
5474e57f 106Read the Hardware Clock and print the time on standard output.
c07ebfa1 107The time shown is always in local time, even if you keep your Hardware Clock
2ed1d701
J
108in UTC. See the
109.B \%\-\-localtime
7eda085c 110option.
2ed1d701 111.sp
5474e57f 112Showing the Hardware Clock time is the default when no function is specified.
2ed1d701
J
113.sp
114The
cb7efbc1 115.B \-\-get
2ed1d701
J
116function also applies drift correction to the time read, based upon the
117information in
118.IR @ADJTIME_PATH@ .
119Do not use this function if the Hardware Clock is being modified by
120anything other than the current operating system's
121.B \%hwclock
122command, such as \%'11\ minute\ mode' or from dual-booting another OS.
123.
cb7efbc1 124.TP
93f9a8e4 125.BR \-s , \ \-\-hctosys
2ed1d701 126Set the System Clock from the Hardware Clock. The time read from the Hardware
cb7efbc1 127Clock is compensated to account for systematic drift before using it to set the
2ed1d701
J
128System Clock. See the discussion below, under
129.BR "The Adjust Function" .
fc56c363 130.sp
2ed1d701
J
131The System Clock must be kept in the UTC timescale for date-time
132applications to work correctly in conjunction with the timezone configured
133for the system. If the Hardware Clock is kept in local time then the time read
134from it must be shifted to the UTC timescale before using it to set the System
135Clock. The
136.B \%\-\-hctosys
137function does this based upon the information in the
138.I @ADJTIME_PATH@
139file or the command line arguments
140.BR \%\-\-localtime " and " \-\-utc .
141Note: no daylight saving adjustment is made. See the discussion below under
142.BR "LOCAL vs UTC" .
143.sp
144The kernel also keeps a timezone value, the
145.B \%\-\-hctosys
146function sets it to the timezone configured for the system. The system
147timezone is configured by the TZ environment variable or the
148.I \%/etc/localtime
149file, as
150.BR \%tzset (3)
22853e4a
KZ
151would interpret them.
152The obsolete tz_dsttime field of the kernel's timezone value is set
2ed1d701
J
153to zero. (For details on what this field used to mean, see
154.BR \%settimeofday (2).)
fc56c363 155.sp
2ed1d701
J
156When used in a startup script, making the
157.B \%\-\-hctosys
158function the first caller of
159.BR \%settimeofday (2)
160from boot, it will set the NTP \%'11\ minute\ mode' timescale via the
161.I \%persistent_clock_is_local
162kernel variable. If the Hardware Clock's timescale configuration is
163changed then a reboot is required to inform the kernel. See the
164discussion below, under
df48a721 165.BR "Automatic Hardware Clock Synchronization by the Kernel" .
fc56c363 166.sp
2ed1d701
J
167This is a good function to use in one of the system startup scripts before the
168file systems are mounted read/write.
fc56c363 169.sp
2ed1d701
J
170This function should never be used on a running system. Jumping system time
171will cause problems, such as, corrupted filesystem timestamps. Also, if
172something has changed the Hardware Clock, like NTP's \%'11\ minute\ mode', then
173.B \%\-\-hctosys
174will set the time incorrectly by including drift compensation.
175.sp
176Drift compensation can be inhibited by setting the drift factor in
177.I @ADJTIME_PATH@
178to zero. This setting will be persistent as long as the
179.BR \%\-\-update\-drift " option is not used with " \%\-\-systohc
180at shutdown (or anywhere else). Another way to inhibit this is by using the
181.BR \%\-\-noadjfile " option when calling the " \%\-\-hctosys
182function. A third method is to delete the
183.IR @ADJTIME_PATH@ " file."
184.B Hwclock
185will then default to using the UTC timescale for the Hardware Clock. If
186the Hardware Clock is ticking local time it will need to be defined in
187the file. This can be done by calling
188.BR hwclock\ \-\-localtime\ \-\-adjust ;
189when the file is not present this command will not actually
190adjust the Clock, but it will create the file with local time
191configured, and a drift factor of zero.
192.sp
193A condition under which inhibiting
194.BR hwclock 's
195drift correction may be desired is when dual-booting multiple operating
196systems. If while this instance of Linux is stopped, another OS changes
197the Hardware Clock's value, then when this instance is started again the
198drift correction applied will be incorrect.
199.sp
200.RB "For " hwclock 's
201drift correction to work properly it is imperative that nothing changes
202the Hardware Clock while its Linux instance is not running.
203.
fd6b7a7f 204.TP
ae4cc2ad
BS
205.B \-\-set
206Set the Hardware Clock to the time given by the
2ed1d701
J
207.BR \-\-date
208option, and update the timestamps in
209.IR @ADJTIME_PATH@ .
210With the
211.B --update-drift
212option (re)calculate the drift factor.
213.
fd6b7a7f 214.TP
88a3372e 215.B \-\-systz
2ed1d701
J
216This is an alternate to the
217.B \%\-\-hctosys
218function that does not read the Hardware Clock nor set the System Clock;
219consequently there is not any drift correction. It is intended to be
220used in a startup script on systems with kernels above version 2.6 where
221you know the System Clock has been set from the Hardware Clock by the
222kernel during boot.
fc56c363 223.sp
2ed1d701
J
224It does the following things that are detailed above in the
225.BR \%\-\-hctosys " function:"
226.RS
227.IP \(bu 2
228Corrects the System Clock timescale to UTC as needed. Only instead of
229accomplishing this by setting the System Clock,
230.B hwclock
231simply informs the kernel and it handles the change.
232.IP \(bu 2
233Sets the kernel's NTP \%'11\ minute\ mode' timescale.
234.IP \(bu 2
235Sets the kernel's timezone.
236.PP
237The first two are only available on the first call of
238.BR \%settimeofday (2)
239after boot. Consequently this option only makes sense when used in a
240startup script. If the Hardware Clocks timescale configuration is
241changed then a reboot would be required to inform the kernel.
242.RE
243.
88a3372e 244.TP
ae4cc2ad 245.BR \-w , \ \-\-systohc
2ed1d701
J
246Set the Hardware Clock from the System Clock, and update the timestamps in
247.IR @ADJTIME_PATH@ .
248With the
249.B --update-drift
250option (re)calculate the drift factor.
251.
2b6fc908 252.TP
ae4cc2ad
BS
253.BR \-V , \ \-\-version
254Display version information and exit.
2ed1d701 255.
d0b76eac 256.TP
5474e57f 257.BR \-h , \ \-\-help
b4362b6f 258Display help text and exit.
2ed1d701 259.
5474e57f 260.SH OPTIONS
2ed1d701 261.
da82f6fe 262.TP
93f9a8e4 263.BI \-\-adjfile= filename
2ed1d701
J
264.RI "Override the default " @ADJTIME_PATH@ " file path."
265.
7eda085c
KZ
266.TP
267.B \-\-badyear
ae4cc2ad 268Indicate that the Hardware Clock is incapable of storing years outside
9abb2685 269the range 1994-1999. There is a problem in some BIOSes (almost all
7eda085c
KZ
270Award BIOSes made between 4/26/94 and 5/31/95) wherein they are unable
271to deal with years after 1999. If one attempts to set the year-of-century
272value to something less than 94 (or 95 in some cases), the value that
273actually gets set is 94 (or 95). Thus, if you have one of these machines,
2ed1d701 274.B \%hwclock
7eda085c
KZ
275cannot set the year after 1999 and cannot use the value of the clock as
276the true time in the normal way.
fc56c363 277.sp
7eda085c 278To compensate for this (without your getting a BIOS update, which would
9abb2685 279definitely be preferable), always use
2ed1d701 280.B \%\-\-badyear
9abb2685 281if you have one of these machines. When
2ed1d701 282.B \%hwclock
7eda085c 283knows it's working with a brain-damaged clock, it ignores the year part of
9abb2685 284the Hardware Clock value and instead tries to guess the year based on the
8d8ea18e 285last calibrated date in the adjtime file, by assuming that date is
9abb2685 286within the past year. For this to work, you had better do a
2ed1d701 287.B \%hwclock\ \-\-set
7eda085c 288or
2ed1d701 289.B \%hwclock\ \-\-systohc
7eda085c 290at least once a year!
fc56c363 291.sp
9abb2685 292Though
2ed1d701 293.B \%hwclock
7eda085c
KZ
294ignores the year value when it reads the Hardware Clock, it sets the
295year value when it sets the clock. It sets it to 1995, 1996, 1997, or
2961998, whichever one has the same position in the leap year cycle as
297the true year. That way, the Hardware Clock inserts leap days where
298they belong. Again, if you let the Hardware Clock run for more than a
299year without setting it, this scheme could be defeated and you could
300end up losing a day.
fc56c363 301.sp
2ed1d701 302.B \%hwclock
9abb2685 303warns you that you probably need
2ed1d701 304.B \%\-\-badyear
9abb2685 305whenever it finds your Hardware Clock set to 1994 or 1995.
2ed1d701 306.
7eda085c 307.TP
2ed1d701 308.BI \%\-\-date= date_string
ae4cc2ad
BS
309You need this option if you specify the
310.B \-\-set
311or
2ed1d701 312.B \%\-\-predict
ae4cc2ad
BS
313functions, otherwise it is ignored.
314It specifies the time to which to set the Hardware Clock, or the
315time for which to predict the Hardware Clock reading.
2ed1d701
J
316The value of this option is used as an argument to the
317.BR date "(1) program's " \-\-date
318option. For example:
319.RS
320.IP "" 4
321.BI "\%hwclock\ \-\-set\ \-\-date='" 2011-08-14\ 16:45:05 '
322.PP
ae4cc2ad 323The argument must be in local time, even if you keep your Hardware Clock in
2ed1d701
J
324UTC. See the
325.B \%\-\-localtime
326option. The argument must not be a relative time like "+5 minutes", because
327.BR \%hwclock 's
328precision depends upon correlation between the argument's value and when
329the enter key is pressed.
330.RE
331.
7eda085c 332.TP
ae4cc2ad
BS
333.B \-\-debug
334Display a lot of information about what
2ed1d701
J
335.B \%hwclock
336is doing internally. Some of its functions are complex and this output
ae4cc2ad 337can help you understand how the program works.
2ed1d701 338.
7eda085c 339.TP
ae4cc2ad 340.B \-\-directisa
2ed1d701
J
341This option is meaningful for: ISA compatible machines including x86, and
342x86_64; and Alpha (which has a similar Hardware Clock interface). For other
343machines, it has no effect. This option tells
344.B \%hwclock
ae4cc2ad
BS
345to use explicit I/O instructions to access the Hardware Clock.
346Without this option,
2ed1d701 347.B \%hwclock
1afe0412
WP
348will use the rtc device, which it assumes to be driven by the RTC device
349driver. As of v2.26 it will no longer automatically use directisa when
350the rtc driver is unavailable; this was causing an unsafe condition that
351could allow two processes to access the Hardware Clock at the same time.
352Direct hardware access from userspace should only be used for testing,
353troubleshooting, and as a last resort when all other methods fail. See
354the
2ed1d701
J
355.BR \-\-rtc " option."
356.
ae4cc2ad 357.TP
2ed1d701
J
358.BR \-f , \ \-\-rtc=\fIfilename\fR
359.RB "Override " \%hwclock 's
360default rtc device file name. Otherwise it will
361use the first one found in this order:
362.in +4
363.br
364.I /dev/rtc
365.br
366.I /dev/rtc0
367.br
368.I /dev/misc/rtc
369.br
370.in
371.RB "For " IA-64:
372.in +4
373.br
374.I /dev/efirtc
375.br
376.I /dev/misc/efirtc
377.in
378.
ae4cc2ad
BS
379.TP
380.B \-\-localtime
2ed1d701
J
381.TQ
382.BR \-u ", " \-\-utc
383Indicate which timescale the Hardware Clock is set to.
fc56c363 384.sp
2ed1d701
J
385The Hardware Clock may be configured to use either the UTC or the local
386timescale, but nothing in the clock itself says which alternative is
387being used. The
388.BR \%\-\-localtime " or " \-\-utc
389options give this information to the
390.B \%hwclock
391command. If you specify the wrong one (or specify neither and take a
392wrong default), both setting and reading the Hardware Clock will be
393incorrect.
fc56c363 394.sp
ae4cc2ad 395If you specify neither
2ed1d701
J
396.BR \-\-utc " nor " \%\-\-localtime
397then the one last given with a set function
398.RB ( \-\-set ", " \%\-\-systohc ", or " \%\-\-adjust ),
399as recorded in
400.IR @ADJTIME_PATH@ ,
401will be used. If the adjtime file doesn't exist, the default is UTC.
402.sp
403Note: daylight saving time changes may be inconsistent when the
404Hardware Clock is kept in local time. See the discussion below under
405.BR "LOCAL vs UTC" .
406.
ae4cc2ad
BS
407.TP
408.B \-\-noadjfile
409Disable the facilities provided by
410.IR @ADJTIME_PATH@ .
2ed1d701 411.B \%hwclock
ae4cc2ad 412will not read nor write to that file with this option. Either
2ed1d701 413.BR \-\-utc " or " \%\-\-localtime
ae4cc2ad 414must be specified when using this option.
2ed1d701 415.
2b6fc908 416.TP
fd6b7a7f 417.B \-\-test
2ed1d701
J
418Do not actually change anything on the system, i.e., the Clocks or
419adjtime file. This is useful, especially in conjunction with
420.BR \%\-\-debug ,
cd950279 421in learning about the internal operations of hwclock.
2ed1d701 422.
cd950279 423.TP
2ed1d701 424.B \-\-update\-drift
cd950279
WP
425Update the Hardware Clock's drift factor in
426.IR @ADJTIME_PATH@ .
427It is used with
2ed1d701 428.BR \-\-set " or " \%\-\-systohc ,
cd950279 429otherwise it is ignored.
2ed1d701
J
430.sp
431A minimum four hour period between settings is required. This is to
432avoid invalid calculations. The longer the period, the more precise the
433resulting drift factor will be.
434.sp
435This option was added in v2.26, because
436it is typical for systems to call
437.B \%hwclock\ \-\-systohc
438at shutdown; with the old behaviour this would automatically
439(re)calculate the drift factor which caused several problems:
440.RS
441.IP \(bu 2
442When using ntpd with an \%'11\ minute\ mode' kernel the drift factor
443would be clobbered to near zero.
444.IP \(bu 2
445It would not allow the use of 'cold' drift correction. With most
446configurations using 'cold' drift will yield favorable results. Cold,
447means when the machine is turned off which can have a significant impact
448on the drift factor.
449.IP \(bu 2
450(Re)calculating drift factor on every shutdown delivers suboptimal
451results. For example, if ephemeral conditions cause the machine to be
452abnormally hot the drift factor calculation would be out of range.
453.PP
454.RB "Having " \%hwclock
455calculate the drift factor is a good starting point, but for optimal
456results it will likely need to be adjusted by directly editing the
457.I @ADJTIME_PATH@
458file. For most configurations once a machine's optimal drift factor is
459crafted it should not need to be changed. Therefore, the old behavior to
460automatically (re)calculate drift was changed and now requires this
461option to be used. See the discussion below, under
462.BR "The Adjust Function" .
463.RE
464.
465.SH OPTIONS FOR ALPHA MACHINES ONLY
466.
467.TP
468.B \-\-arc
469This option is equivalent to
470.BI \%\-\-epoch= 1980
471and is used to specify the most common epoch on Alphas
472with ARC console (but Ruffians have an epoch of 1900).
473.
474.TP
475.BI \-\-epoch= year
476Specifies the year which is the beginning of the Hardware Clock's epoch,
477that is the number of years into AD to which a zero value in the
478Hardware Clock's year counter refers. It is used together with the
479.B \%\-\-setepoch
1afe0412 480option to set the kernel's idea of the epoch of the Hardware Clock.
2ed1d701
J
481.sp
482For example, on a Digital Unix machine:
483.RS
484.IP "" 4
485.BI hwclock\ \-\-setepoch\ \-\-epoch= 1952
486.RE
487.
fd6b7a7f 488.TP
2ed1d701
J
489.B \-\-funky\-toy
490.TQ
491.B \-\-jensen
492These two options specify what kind of Alpha machine you have. They
493are invalid if you do not have an Alpha and are usually unnecessary
494if you do;
495.B \%hwclock
496should be able to determine what it is running on when
497.I \%/proc
498is mounted.
499.sp
500.RB "The " \%\-\-jensen
501option is used for Jensen models;
502.B \%\-\-funky\-toy
503means that the machine requires the UF bit instead of the UIP bit in
504the Hardware Clock to detect a time transition. "Toy" in the option
505name refers to the Time Of Year facility of the machine.
506.
507.TP
508.B \-\-srm
509This option is equivalent to
510.BI \%\-\-epoch= 1900
511and is used to specify the most common epoch on Alphas
512with SRM console.
513.
fd6b7a7f 514.SH NOTES
2ed1d701 515.
ae4cc2ad 516.SS Clocks in a Linux System
fd6b7a7f 517.PP
2ed1d701 518There are two types of date-time clocks:
fd6b7a7f 519.PP
9abb2685 520.B The Hardware Clock:
2ed1d701
J
521This clock is an independent hardware device, with its own power domain
522(battery, capacitor, etc), that operates when the machine is powered off,
523or even unplugged.
ae4cc2ad 524.PP
2ed1d701
J
525On an ISA compatible system, this clock is specified as part of the ISA
526standard. A control program can read or set this clock only to a whole
527second, but it can also detect the edges of the 1 second clock ticks, so
528the clock actually has virtually infinite precision.
fd6b7a7f
KZ
529.PP
530This clock is commonly called the hardware clock, the real time clock,
531the RTC, the BIOS clock, and the CMOS clock. Hardware Clock, in its
9abb2685 532capitalized form, was coined for use by
2ed1d701
J
533.BR \%hwclock .
534The Linux kernel also refers to it as the persistent clock.
fd6b7a7f 535.PP
2ed1d701 536Some non-ISA systems have a few real time clocks with
88681c5f
KZ
537only one of them having its own power domain.
538A very low power external I2C or SPI clock chip might be used with a
539backup battery as the hardware clock to initialize a more functional
540integrated real-time clock which is used for most other purposes.
541.PP
2ed1d701
J
542.B The System Clock:
543This clock is part of the Linux kernel and is driven by
2b6fc908 544a timer interrupt. (On an ISA machine, the timer interrupt is part of
ae4cc2ad 545the ISA standard.) It has meaning only while Linux is running on the
2b6fc908
KZ
546machine. The System Time is the number of seconds since 00:00:00
547January 1, 1970 UTC (or more succinctly, the number of seconds since
2ed1d701 5481969 UTC). The System Time is not an integer, though. It has virtually
2b6fc908 549infinite precision.
fd6b7a7f
KZ
550.PP
551The System Time is the time that matters. The Hardware Clock's basic
2ed1d701
J
552purpose is to keep time when Linux is not running so that the System
553Clock can be initialized from it at boot. Note that in DOS, for which
554ISA was designed, the Hardware Clock is the only real time clock.
fd6b7a7f
KZ
555.PP
556It is important that the System Time not have any discontinuities such as
9abb2685 557would happen if you used the
2ed1d701 558.BR \%date (1)
fd6b7a7f
KZ
559program to set it while the system is running. You can, however, do whatever
560you want to the Hardware Clock while the system is running, and the next
561time Linux starts up, it will do so with the adjusted time from the Hardware
2ed1d701
J
562Clock. Note: currently this is not possible on most systems because
563.B \%hwclock\ \-\-systohc
564is called at shutdown.
5c36a0eb 565.PP
2ed1d701
J
566The Linux kernel's timezone is set by
567.BR hwclock .
5c36a0eb
KZ
568But don't be misled -- almost nobody cares what timezone the kernel
569thinks it is in. Instead, programs that care about the timezone
570(perhaps because they want to display a local time for you) almost
571always use a more traditional method of determining the timezone: They
2ed1d701
J
572use the TZ environment variable or the
573.I \%/etc/localtime
574file, as explained in the man page for
575.BR \%tzset (3).
8db424dc 576However, some programs and fringe parts of the Linux kernel such as filesystems
2ed1d701 577use the kernel's timezone value. An example is the vfat filesystem. If the
8db424dc 578kernel timezone value is wrong, the vfat filesystem will report and set the
2ed1d701 579wrong timestamps on files. Another example is the kernel's NTP \%'11\ minute\ mode.'
8db424dc 580If the kernel's timezone value and/or the
2ed1d701
J
581.I \%persistent_clock_is_local
582variable are wrong, then the Hardware Clock will be set incorrectly
583by \%'11\ minute\ mode.' See the discussion below, under
df48a721 584.BR "Automatic Hardware Clock Synchronization by the Kernel" .
5c36a0eb 585.PP
2ed1d701
J
586.B \%hwclock
587sets the kernel's timezone to the value indicated by TZ or
588.IR \%/etc/localtime " with the"
589.BR \%\-\-hctosys " or " \%\-\-systz " functions."
5c36a0eb 590.PP
2ed1d701 591The kernel's timezone value actually consists of two parts: 1) a field
22853e4a
KZ
592tz_minuteswest indicating how many minutes local time (not adjusted
593for DST) lags behind UTC, and 2) a field tz_dsttime indicating
594the type of Daylight Savings Time (DST) convention that is in effect
595in the locality at the present time.
596This second field is not used under Linux and is always zero.
2ed1d701
J
597See also
598.BR \%settimeofday (2).
599.
ae4cc2ad 600.SS User access and setuid
a6ccf39b
SK
601.PP
602Sometimes, you need to install
2ed1d701 603.B \%hwclock
ae4cc2ad 604setuid root. If you want users other than the superuser to be able to
a6ccf39b 605display the clock value using the direct ISA I/O method, install it setuid
2ed1d701
J
606root. If you have the rtc device interface on your system, or are on a non-ISA
607compatible system, there is probably no need for users to have the direct
608ISA I/O method, so do not bother. See the
609.BR \-\-rtc " option."
ae4cc2ad 610.PP
a6ccf39b 611In any case, hwclock will not allow you to set anything unless you have the
ae4cc2ad
BS
612superuser real uid. (This restriction is not necessary if you haven't
613installed setuid root, but it's there for now.)
2ed1d701
J
614.
615.SS Hardware Clock Access Methods
2b6fc908 616.PP
2ed1d701 617.B \%hwclock
1afe0412
WP
618uses many different ways to get and set Hardware Clock values. The most
619normal way is to do I/O to the rtc device special file, which is
620presumed to be driven by the rtc device driver. Also, Linux systems
621using the rtc framework with udev, are capable of supporting multiple
622Hardware Clocks. This may bring about the need to override the default
623rtc device by specifying one with the
2ed1d701 624.BR \-\-rtc " option."
2b6fc908 625.PP
1afe0412
WP
626However, this method is not always available as older systems do not
627have an rtc driver. On these systems, the method of accessing the
628Hardware Clock depends on the system hardware.
2b6fc908 629.PP
2ed1d701
J
630On an ISA compatible system,
631.B \%hwclock
7eda085c
KZ
632can directly access the "CMOS memory" registers that
633constitute the clock, by doing I/O to Ports 0x70 and 0x71. It does
634this with actual I/O instructions and consequently can only do it if
1afe0412
WP
635running with superuser effective userid. This method may be used by
636specifying the
637.BR \%\-\-directisa " option."
ae4cc2ad 638.PP
2b6fc908 639This is a really poor method of accessing the clock, for all the
ae4cc2ad 640reasons that userspace programs are generally not supposed to do
2ed1d701
J
641direct I/O and disable interrupts.
642.B \%hwclock
1afe0412
WP
643provides it for testing, troubleshooting, and because it may be the
644only method available on ISA compatible and Alpha systems which do not
645have a working rtc device driver.
646.PP
647In the case of a Jensen Alpha, there is no way for
648.B \%hwclock
649to execute those I/O instructions, and so it uses instead the
650.I \%/dev/port
651device special file, which provides almost as low-level an interface to
652the I/O subsystem.
2b6fc908
KZ
653.PP
654On an m68k system,
2ed1d701
J
655.B \%hwclock
656can access the clock with the console driver, via the device special file
657.IR \%/dev/tty1 .
ae4cc2ad 658.SS The Adjust Function
fd6b7a7f
KZ
659.PP
660The Hardware Clock is usually not very accurate. However, much of its
7eda085c 661inaccuracy is completely predictable - it gains or loses the same amount
fd6b7a7f 662of time every day. This is called systematic drift.
2ed1d701 663.BR \%hwclock "'s " \%\-\-adjust
cb7efbc1
WP
664function lets you apply systematic drift corrections to the
665Hardware Clock.
fd6b7a7f 666.PP
9abb2685 667It works like this:
2ed1d701 668.BR \%hwclock " keeps a file,"
2ad21963 669.IR @ADJTIME_PATH@ ,
fd6b7a7f
KZ
670that keeps some historical information. This is called the adjtime file.
671.PP
9abb2685 672Suppose you start with no adjtime file. You issue a
2ed1d701 673.B \%hwclock\ \-\-set
9abb2685 674command to set the Hardware Clock to the true current time.
2ed1d701 675.B \%hwclock
9abb2685 676creates the adjtime file and records in it the current time as the
fd6b7a7f 677last time the clock was calibrated.
df48a721 678Five days later, the clock has gained 10 seconds, so you issue a
2ed1d701 679.B \%hwclock\ \-\-set\ \-\-update\-drift
9abb2685 680command to set it back 10 seconds.
2ed1d701 681.B \%hwclock
fd6b7a7f
KZ
682updates the adjtime file to show the current time as the last time the
683clock was calibrated, and records 2 seconds per day as the systematic
684drift rate. 24 hours go by, and then you issue a
2ed1d701 685.B \%hwclock\ \-\-adjust
9abb2685 686command.
2ed1d701 687.B \%hwclock
fd6b7a7f
KZ
688consults the adjtime file and sees that the clock gains 2 seconds per
689day when left alone and that it has been left alone for exactly one
690day. So it subtracts 2 seconds from the Hardware Clock. It then
691records the current time as the last time the clock was adjusted.
df48a721 692Another 24 hours go by and you issue another
2ed1d701
J
693.BR \%hwclock\ \-\-adjust .
694.B \%hwclock
fd6b7a7f
KZ
695does the same thing: subtracts 2 seconds and updates the adjtime file
696with the current time as the last time the clock was adjusted.
697.PP
cd950279 698When you use the
2ed1d701
J
699.BR \%\-\-update\-drift " option with " \-\-set " or " \%\-\-systohc ,
700the systematic drift rate is (re)calculated by comparing the fully drift
701corrected current Hardware Clock time with the new set time, from that
702it derives the 24 hour drift rate based on the last calibrated timestamp
703from the adjtime file. This updated drift factor is then saved in
cd950279 704.IR @ADJTIME_PATH@ .
fd6b7a7f 705.PP
cb7efbc1
WP
706A small amount of error creeps in when
707the Hardware Clock is set, so
2ed1d701 708.B \%\-\-adjust
cb7efbc1
WP
709refrains from making any adjustment that is less
710than 1 second. Later on, when you request an adjustment again, the accumulated
711drift will be more than 1 second and
2ed1d701 712.B \%\-\-adjust
cb7efbc1
WP
713will make the adjustment including any fractional amount.
714.PP
2ed1d701 715.B \%hwclock\ \-\-hctosys
cb7efbc1 716also uses the adjtime file data to compensate the value read from the Hardware
2ed1d701
J
717Clock before using it to set the System Clock. It does not share the 1 second
718limitation of
719.BR \%\-\-adjust ,
720and will correct sub-second drift values immediately. It does not
721change the Hardware Clock time nor the adjtime file. This may eliminate
722the need to use
723.BR \%\-\-adjust ,
724unless something else on the system needs the Hardware Clock to be
725compensated.
726.
727.SS The Adjtime File
728While named for its historical purpose of controlling adjustments only,
729it actually contains other information used by
730.B hwclock
731from one invocation to the next.
7eda085c 732.PP
5c36a0eb 733The format of the adjtime file is, in ASCII:
fd6b7a7f 734.PP
df48a721
BS
735Line 1: Three numbers, separated by blanks: 1) the systematic drift rate
736in seconds per day, floating point decimal; 2) the resulting number of
5c36a0eb
KZ
737seconds since 1969 UTC of most recent adjustment or calibration,
738decimal integer; 3) zero (for compatibility with
2ed1d701 739.BR \%clock (8))
7eda085c 740as a decimal integer.
fd6b7a7f 741.PP
df48a721 742Line 2: One number: the resulting number of seconds since 1969 UTC of most
7eda085c
KZ
743recent calibration. Zero if there has been no calibration yet or it
744is known that any previous calibration is moot (for example, because
9abb2685 745the Hardware Clock has been found, since that calibration, not to
7eda085c
KZ
746contain a valid time). This is a decimal integer.
747.PP
9abb2685 748Line 3: "UTC" or "LOCAL". Tells whether the Hardware Clock is set to
7eda085c 749Coordinated Universal Time or local time. You can always override this
9abb2685 750value with options on the
2ed1d701 751.B \%hwclock
7eda085c 752command line.
fd6b7a7f 753.PP
9abb2685 754You can use an adjtime file that was previously used with the
2ed1d701
J
755.BR \%clock "(8) program with " \%hwclock .
756.
ae4cc2ad
BS
757.SS Automatic Hardware Clock Synchronization by the Kernel
758.PP
9abb2685 759You should be aware of another way that the Hardware Clock is kept
5c36a0eb 760synchronized in some systems. The Linux kernel has a mode wherein it
9abb2685 761copies the System Time to the Hardware Clock every 11 minutes.
5c36a0eb 762This is a good mode to use when you are using something sophisticated
2ed1d701 763like NTP to keep your System Clock synchronized. (NTP is a way to keep
5c36a0eb 764your System Time synchronized either to a time server somewhere on the
ae4cc2ad
BS
765network or to a radio clock hooked up to your system. See RFC 1305.)
766.PP
2ed1d701
J
767This mode (we'll call it \%'11\ minute\ mode') is off until something
768turns it on. The NTP daemon ntpd is one thing that turns it on. You
5c36a0eb 769can turn it off by running anything, including
2ed1d701
J
770.BR \%hwclock\ \-\-hctosys ,
771that sets the System Clock the old fashioned way. However, if the NTP daemon is
8db424dc
WP
772still running, it will turn 11 minute mode back on again the next time it
773synchronizes the System Clock.
ae4cc2ad 774.PP
3400dbba
WP
775When \%'11\ minute\ mode' is active the 64 bit of the kernel's
776.I time_status
777variable is unset. The status variable can be checked with the
778.BR \%adjtimex\ --print " or " \%ntptime " commands."
779.PP
2ed1d701
J
780If your system runs with \%'11\ minute\ mode' on, it may need to use either
781.BR \%\-\-hctosys " or " \%\-\-systz
d1bfa4ef 782in a startup script, especially if the Hardware Clock is configured to use
2ed1d701
J
783the local timescale. Unless the kernel is informed of what timescale the
784Hardware Clock is using, it may clobber it with the wrong one. The kernel
785uses UTC by default.
786.PP
787The first userspace command to set the System Clock informs the
df48a721 788kernel what timescale the Hardware Clock is using. This happens via the
2ed1d701 789.I \%persistent_clock_is_local
df48a721 790kernel variable. If
2ed1d701 791.BR \%\-\-hctosys " or " \%\-\-systz
8db424dc 792is the first, it will set this variable according to the adjtime file or the
df48a721 793appropriate command-line argument. Note that when using this capability and the
8db424dc
WP
794Hardware Clock timescale configuration is changed, then a reboot is required to
795notify the kernel.
2ed1d701
J
796.PP
797.B \%hwclock\ \-\-adjust
798should not be used with NTP \%'11\ minute\ mode.'
799.
ae4cc2ad
BS
800.SS ISA Hardware Clock Century value
801.PP
7eda085c 802There is some sort of standard that defines CMOS memory Byte 50 on an ISA
9abb2685 803machine as an indicator of what century it is.
2ed1d701 804.B \%hwclock
7eda085c
KZ
805does not use or set that byte because there are some machines that
806don't define the byte that way, and it really isn't necessary anyway,
807since the year-of-century does a good job of implying which century it
808is.
ae4cc2ad 809.PP
9abb2685 810If you have a bona fide use for a CMOS century byte, contact the
2ed1d701 811.B \%hwclock
7eda085c 812maintainer; an option may be appropriate.
ae4cc2ad 813.PP
7eda085c
KZ
814Note that this section is only relevant when you are using the "direct
815ISA" method of accessing the Hardware Clock.
88681c5f
KZ
816ACPI provides a standard way to access century values, when they
817are supported by the hardware.
2ed1d701
J
818.
819.SH DATE-TIME CONFIGURATION
820.in +4
821.SS Keeping Time without External Synchronization
822.in
823.PP
824This discussion is based on the following conditions:
825.IP \(bu 2
826Nothing is running that alters the date-time clocks, e.g.,
827.BR \%ntpd "(1), cron jobs, et al."
828.IP \(bu 2
829The system timezone is configured for the correct local time. See below
830.BR "POSIX vs 'RIGHT'" .
831.IP \(bu 2
832Early in startup the following are called in this order:
833.br
834.BI \%adjtimex\ \-\-tick \ <value>\ \-\-frequency \ <value>
835.br
836.B \%hwclock\ \-\-hctosys
837.IP \(bu 2
838During shutdown the following is called:
839.br
840.B \%hwclock\ \-\-systohc
841.PP
37f8d848
WP
842.in +4
843.BR * " Systems without " adjtimex " may use " ntptime .
844.in
845.PP
2ed1d701
J
846Whether maintaining precision time with
847.BR \%ntpd (1)
848or not, it makes sense to configure the system to keep reasonably good
849date-time on its own.
850.PP
851The first step in making that happen is having a clear understanding of
852the big picture. There are two completely separate hardware devices
853running at their own speed and drifting away from the 'correct' time at
854their own rates. The methods and software for drift correction are
855different for each of them. However, most systems are configured to
856exchange values between these two clocks at startup and shutdown. Now
a55f60a1 857the individual device's time keeping errors are transferred back and
2ed1d701
J
858forth between each other. Attempt to configure drift correction for only
859one of them, and the other's drift will be overlaid upon it. If the big
860picture is not kept in mind, confusion will soon ensue.
861.PP
862This problem can be avoided when configuring drift correction for the
863System Clock by simply not shutting down the machine. This, plus the
864fact that all of
865.BR \%hwclock 's
866precision (including calculating drift factors) depends upon the System
867Clock's rate being correct, means that configuration of the System Clock
868should be done first.
869.PP
870The System Clock drift is corrected with the
871.BR \%adjtimex "(8) command's " \-\-tick " and " \%\-\-frequency
872options. These two work together, tick is the course adjustment and
37f8d848
WP
873frequency is the fine adjustment. (For system that do not have an
874.BR \%adjtimex " package,"
875.BI \%ntptime\ \-f\ <ppm>
876may be use instead.)
2ed1d701
J
877.PP
878Some Linux distributions attempt to automatically calculate the System
879Clock drift with
880.BR \%adjtimex 's
881compare operation. Trying to correct one
882drifting clock by using another drifting clock as a reference is akin to
883a dog trying to catch its own tail. Success may happen eventually, but
884great effort and frustration will likely precede it. This automation may
885yield an improvement over no configuration, but expecting optimum
886results would be in error. A better choice for manual configuration
887would be
888.BR \%adjtimex 's " \-\-log " options.
889.PP
890It may be more effective to simply track the System Clock drift with
187c2b8e 891.BR \%sntp ", or " \%date\ \-Ins
2ed1d701
J
892and a precision timepiece, and then calculate the correction manually.
893.PP
894After setting the tick and frequency values, continue to test and refine the
895adjustments until the System Clock keeps good time. See
896.BR \%adjtimex (8)
897for more information and the example demonstrating manual drift
898calculations.
899.PP
900Once the System Clock is ticking smoothly, move on to the Hardware Clock.
901.PP
902As a rule, cold drift will work best for most use cases. This should be
903true even for 24/7 machines whose normal downtime consists of a reboot.
904In that case the drift factor value makes little difference, but on the
905rare occasion that the machine is shutdown for an extended period then
906cold drift should yield better results.
907.PP
908.B Steps to calculate cold drift:
909.IP 1 2
910.RB "Confirm that " ntpd "(1) will not be launched at startup."
911.IP 2 2
912.RI The " System Clock " "time must be correct at shutdown!"
913.IP 3 2
914Shutdown the system.
915.IP 4 2
916Let an extended period pass without changing the Hardware Clock.
917.IP 5 2
918Start the system.
919.IP 6 2
920.RB "Immediately use " hwclock " to set the correct time with the"
921.BR \%\-\-update\-drift " option."
922.PP
923Note: if step six uses
924.RB \%\-\-systohc ,
925then the System Clock must be set correctly (step 6a) just before doing so.
926.PP
927.RB "Having " hwclock
928calculate the drift factor is a good starting point, but for optimal
929results it will likely need to be adjusted by directly editing the
930.I @ADJTIME_PATH@
931file. Continue to test and refine the drift factor until the Hardware
932Clock is corrected properly at startup. To check this, first make sure
933that the System Time is correct before shutdown and then use
187c2b8e 934.BR \%sntp ", or " \%date\ \-Ins
2ed1d701
J
935and a precision timepiece, immediately after startup.
936.PP
937Both clocks typically use a quartz crystal oscillator. Crystals are
938used for reference oscillators in electronics because by most measures
939they produce a very clean and stable sine wave. Their greatest
940shortcoming is that they have a Positive Temperature Coefficient;
941meaning that their frequency increases as the temperature increases and
942vise versa. Therefore, both the Hardware and System Clock's drift rate
943changes with intrinsic and extrinsic machine temperatures. These
944characteristics will vary by machine depending upon its design.
945.PP
946Drift correction strategies are many, but as a general guide the goal
947would be to find a longterm average. A year long average to take into
948account seasonal ambient temperature shifts may be a good target period.
949So perhaps the date-time advances a bit in the summer and declines a bit
950in the winter, but at the end of a year it balances to zero.
951.PP
952If this is beginning to sound futile, it is not. Left on its own a
953machine can lose 3 seconds per day or more. Accumulated drift over a
954year may easily exceed half an hour. Using carefully crafted drift
955corrections can make a significant improvement in a machine's ability to
956keep reasonably good date-time.
957.
958.SS LOCAL vs UTC
959Keeping the Hardware Clock in a local timescale causes inconsistent
960daylight saving time results:
961.IP \(bu 2
962If Linux is running during a daylight saving time change, the time
963written to the Hardware Clock will be adjusted for the change.
964.IP \(bu 2
965If Linux is NOT running during a daylight saving time change, the time
966read from the Hardware Clock will NOT be adjusted for the change.
967.PP
968The Hardware Clock on an ISA compatible system keeps only a date and time,
969it has no concept of timezone nor daylight saving. Therefore, when
970.B hwclock
971is told that it is in local time, it assumes it is in the 'correct'
972local time and makes no adjustments to the time read from it.
973.PP
974Linux handles daylight saving time changes transparently only when the
975Hardware Clock is kept in the UTC timescale. Doing so is made easy for
976system administrators as
977.B \%hwclock
978uses local time for its output and as the argument to the
979.BR \%\-\-date " option."
980.PP
981POSIX systems, like Linux, are designed to have the System Clock operate
982in the UTC timescale. The Hardware Clock's purpose is to initialize the
983System Clock, so also keeping it in UTC makes sense.
984.PP
985Linux does, however, attempt to accommodate the Hardware Clock being in
986the local timescale. This is primarily for dual-booting with older
987versions of MS Windows. From Windows 7 on, the RealTimeIsUniversal
988registry key is supposed to be working properly so that its Hardware
989Clock can be kept in UTC.
990.
991.SS POSIX vs 'RIGHT'
992A discussion on date-time configuration would be incomplete without
993addressing timezones, this is mostly well covered by
994.BR tzset (3).
995One area that seems to have no documentation is the 'right'
440afddb 996directory of the Time Zone Database, sometimes called tz or zoneinfo.
2ed1d701
J
997.PP
998There are two separate databases in the zoneinfo system, posix
440b5296 999and 'right'. 'Right' (now named zoneinfo\-leaps) includes leap seconds and posix
440afddb
WP
1000does not. To use the 'right' database the System Clock must be set to
1001\%(UTC\ +\ leap seconds), which is equivalent to \%(TAI\ \-\ 10). This
1002allows calculating the
2ed1d701
J
1003exact number of seconds between two dates that cross a leap second
1004epoch. The System Clock is then converted to the correct civil time,
1005including UTC, by using the 'right' timezone files which subtract the
1006leap seconds. Note: this configuration is considered experimental and is
1007known to have issues.
1008.PP
1009To configure a system to use a particular database all of the files
1010located in its directory must be copied to the root of
1011.IR \%/usr/share/zoneinfo .
1012Files are never used directly from the posix or 'right' subdirectories, e.g.,
1013.RI \%TZ=' right/Europe/Dublin '.
1014This habit was becoming so common that the upstream zoneinfo project
1015restructured the system's file tree by moving the posix and 'right'
1016subdirectories out of the zoneinfo directory and into sibling directories:
440b5296 1017.PP
2ed1d701
J
1018.in +2
1019.I /usr/share/zoneinfo
1020.br
440b5296 1021.I /usr/share/zoneinfo\-posix
2ed1d701 1022.br
440b5296 1023.I /usr/share/zoneinfo\-leaps
2ed1d701
J
1024.PP
1025Unfortunately, some Linux distributions are changing it back to the old
1026tree structure in their packages. So the problem of system
1027administrators reaching into the 'right' subdirectory persists. This
1028causes the system timezone to be configured to include leap seconds
1029while the zoneinfo database is still configured to exclude them. Then
1030when an application such as a World Clock needs the South_Pole timezone
1031file; or an email MTA, or
1032.B hwclock
1033needs the UTC timezone file; they fetch it from the root of
1034.I \%/usr/share/zoneinfo
1035, because that is what they are supposed to do. Those files exclude leap
1036seconds, but the System Clock now includes them, causing an incorrect
1037time conversion.
1038.PP
1039Attempting to mix and match files from these separate databases will not
1040work, because they each require the System Clock to use a different
1041timescale. The zoneinfo database must be configured to use either posix
ea6b197e
WP
1042or 'right', as described above, or by assigning a database path to the
1043.SB TZDIR
1044environment variable.
1045.SH ENVIRONMENT
1046.TP
1047.B TZ
1048If this variable is set its value takes precedence over the system
1049configured timezone.
1050.TP
1051.B TZDIR
1052If this variable is set its value takes precedence over the system
1053configured timezone database directory path.
fd6b7a7f 1054.SH FILES
073971e9 1055.TP
2ad21963 1056.I @ADJTIME_PATH@
073971e9
WP
1057The configuration and state file for hwclock.
1058.TP
2ed1d701 1059.I /etc/localtime
073971e9
WP
1060The system timezone file.
1061.TP
1062.I /usr/share/zoneinfo/
1063The system timezone database directory.
1064.PP
1065Device files
1066.B hwclock
1067may try for Hardware Clock access:
2ed1d701 1068.br
7eda085c 1069.I /dev/rtc
2ed1d701 1070.br
88681c5f 1071.I /dev/rtc0
2ed1d701
J
1072.br
1073.I /dev/misc/rtc
1074.br
1075.I /dev/efirtc
1076.br
1077.I /dev/misc/efirtc
1078.br
7eda085c 1079.I /dev/port
2ed1d701 1080.br
7eda085c 1081.I /dev/tty1
7eda085c 1082.SH "SEE ALSO"
7eda085c 1083.BR date (1),
2ed1d701 1084.BR adjtimex (8),
7eda085c
KZ
1085.BR gettimeofday (2),
1086.BR settimeofday (2),
1087.BR crontab (1),
1088.BR tzset (3)
2ed1d701 1089.
fd6b7a7f 1090.SH AUTHORS
63cccae4 1091Written by Bryan Henderson, September 1996 (bryanh@giraffe-data.com),
2b6fc908 1092based on work done on the
2ed1d701 1093.BR \%clock (8)
9abb2685 1094program by Charles Hedrick, Rob Hooft, and Harald Koenig.
7eda085c 1095See the source code for complete history and credits.
2ed1d701 1096.
86d62711 1097.SH AVAILABILITY
601d12fb
KZ
1098The hwclock command is part of the util-linux package and is available from
1099ftp://ftp.kernel.org/pub/linux/utils/util-linux/.