1HWCLOCK(8) System Administration HWCLOCK(8)
2
3
4
6 hwclock - query or set the hardware clock (RTC)
7
9 hwclock [function] [option...]
10
11
13 hwclock is a tool for accessing the Hardware Clock. You can display
14 the current time, set the Hardware Clock to a specified time, set the
15 Hardware Clock from the System Time, or set the System Time from the
16 Hardware Clock.
17
18 You can also run hwclock periodically to add or subtract time from the
19 Hardware Clock to compensate for systematic drift (where the clock con‐
20 sistently loses or gains time at a certain rate when left to run).
21
22
24 You need exactly one of the following options to tell hwclock what
25 function to perform:
26
27 -r, --show
28 Read the Hardware Clock and print the time on standard output.
29 The time shown is always in local time, even if you keep your
30 Hardware Clock in Coordinated Universal Time. See the --utc
31 option. Showing the Hardware Clock time is the default when no
32 function is specified.
33
34
35 --set Set the Hardware Clock to the time given by the --date option.
36
37 -s, --hctosys
38 Set the System Time from the Hardware Clock.
39
40 Also set the kernel's timezone value to the local timezone as
41 indicated by the TZ environment variable and/or /usr/share/zone‐
42 info, as tzset(3) would interpret them. The obsolete tz_dsttime
43 field of the kernel's timezone value is set to DST_NONE. (For
44 details on what this field used to mean, see settimeofday(2).)
45
46 This is a good option to use in one of the system startup
47 scripts.
48
49 -w, --systohc
50 Set the Hardware Clock to the current System Time.
51
52 --systz
53 Set the kernel's timezone and reset the System Time based on the
54 current timezone.
55
56 The system time is only reset on the first call after boot.
57
58 The local timezone is taken to be what is indicated by the TZ
59 environment variable and/or /usr/share/zoneinfo, as tzset(3)
60 would interpret them. The obsolete tz_dsttime field of the ker‐
61 nel's timezone value is set to DST_NONE. (For details on what
62 this field used to mean, see settimeofday(2).)
63
64 This is an alternate option to --hctosys that does not read the
65 hardware clock, and may be used in system startup scripts for
66 recent 2.6 kernels where you know the System Time contains the
67 Hardware Clock time. If the Hardware Clock is already in UTC, it
68 is not reset.
69
70 --adjust
71 Add or subtract time from the Hardware Clock to account for sys‐
72 tematic drift since the last time the clock was set or adjusted.
73 See discussion below.
74
75 --getepoch
76 Print the kernel's Hardware Clock epoch value to standard out‐
77 put. This is the number of years into AD to which a zero year
78 value in the Hardware Clock refers. For example, if you are
79 using the convention that the year counter in your Hardware
80 Clock contains the number of full years since 1952, then the
81 kernel's Hardware Clock epoch value must be 1952.
82
83 This epoch value is used whenever hwclock reads or sets the
84 Hardware Clock.
85
86 --setepoch
87 Set the kernel's Hardware Clock epoch value to the value speci‐
88 fied by the --epoch option. See the --getepoch option for
89 details.
90
91
92 --predict
93 Predict what the RTC will read at time given by the --date
94 option based on the adjtime file. This is useful for example if
95 you need to set an RTC wakeup time to distant future and want to
96 account for the RTC drift.
97
98 -c, --compare
99 Periodically compare the Hardware Clock to the System Time and
100 output the difference every 10 seconds. This will also print
101 the frequency offset and tick.
102
103 -h, --help
104 Display a help text and exit.
105
106 -V, --version
107 Display the version of hwclock and exit.
108
109
111 The first two options apply to just a few specific functions, the oth‐
112 ers apply to most functions.
113
114 --date=date_string
115 You need this option if you specify the --set or --predict func‐
116 tions, otherwise it is ignored. It specifies the time to which
117 to set the Hardware Clock, or the time for which to predict the
118 Hardware Clock reading. The value of this option is an argument
119 to the date(1) program. For example:
120
121 hwclock --set --date="2011-08-14 16:45:05"
122
123 The argument must be in local time, even if you keep your Hard‐
124 ware Clock in Coordinated Universal time. See the --utc option.
125
126
127 --epoch=year
128 Specifies the year which is the beginning of the Hardware
129 Clock's epoch, that is the number of years into AD to which a
130 zero value in the Hardware Clock's year counter refers. It is
131 used together with the --setepoch option to set the kernel's
132 idea of the epoch of the Hardware Clock, or otherwise to specify
133 the epoch for use with direct ISA access.
134
135 For example, on a Digital Unix machine:
136
137 hwclock --setepoch --epoch=1952
138
139
140 -u, --utc
141
142 --localtime
143 Indicates that the Hardware Clock is kept in Coordinated Univer‐
144 sal Time or local time, respectively. It is your choice whether
145 to keep your clock in UTC or local time, but nothing in the
146 clock tells which you've chosen. So this option is how you give
147 that information to hwclock.
148
149 If you specify the wrong one of these options (or specify nei‐
150 ther and take a wrong default), both setting and querying of the
151 Hardware Clock will be messed up.
152
153 If you specify neither --utc nor --localtime, the default is
154 whichever was specified the last time hwclock was used to set
155 the clock (i.e. hwclock was successfully run with the --set,
156 --systohc, or --adjust options), as recorded in the adjtime
157 file. If the adjtime file doesn't exist, the default is UTC
158 time.
159
160
161 --noadjfile
162 Disables the facilities provided by /etc/adjtime. hwclock will
163 not read nor write to that file with this option. Either --utc
164 or --localtime must be specified when using this option.
165
166
167 --adjfile=filename
168 Overrides the default /etc/adjtime.
169
170
171 -f, --rtc=filename
172 Overrides the default /dev file name, which is /dev/rtc on many
173 platforms but may be /dev/rtc0, /dev/rtc1, and so on.
174
175
176 --directisa
177 This option is meaningful only on an ISA machine or an Alpha
178 (which implements enough of ISA to be, roughly speaking, an ISA
179 machine for hwclock's purposes). For other machines, it has no
180 effect. This option tells hwclock to use explicit I/O instruc‐
181 tions to access the Hardware Clock. Without this option,
182 hwclock will try to use the /dev/rtc device (which it assumes to
183 be driven by the RTC device driver). If it is unable to open
184 the device (for reading), it will use the explicit I/O instruc‐
185 tions anyway.
186
187
188 --badyear
189 Indicates that the Hardware Clock is incapable of storing years
190 outside the range 1994-1999. There is a problem in some BIOSes
191 (almost all Award BIOSes made between 4/26/94 and 5/31/95)
192 wherein they are unable to deal with years after 1999. If one
193 attempts to set the year-of-century value to something less than
194 94 (or 95 in some cases), the value that actually gets set is 94
195 (or 95). Thus, if you have one of these machines, hwclock can‐
196 not set the year after 1999 and cannot use the value of the
197 clock as the true time in the normal way.
198
199 To compensate for this (without your getting a BIOS update,
200 which would definitely be preferable), always use --badyear if
201 you have one of these machines. When hwclock knows it's working
202 with a brain-damaged clock, it ignores the year part of the
203 Hardware Clock value and instead tries to guess the year based
204 on the last calibrated date in the adjtime file, by assuming
205 that date is within the past year. For this to work, you had
206 better do a hwclock --set or hwclock --systohc at least once a
207 year!
208
209 Though hwclock ignores the year value when it reads the Hardware
210 Clock, it sets the year value when it sets the clock. It sets
211 it to 1995, 1996, 1997, or 1998, whichever one has the same
212 position in the leap year cycle as the true year. That way, the
213 Hardware Clock inserts leap days where they belong. Again, if
214 you let the Hardware Clock run for more than a year without set‐
215 ting it, this scheme could be defeated and you could end up los‐
216 ing a day.
217
218 hwclock warns you that you probably need --badyear whenever it
219 finds your Hardware Clock set to 1994 or 1995.
220
221
222 --srm This option is equivalent to --epoch=1900 and is used to specify
223 the most common epoch on Alphas with SRM console.
224
225 --arc This option is equivalent to --epoch=1980 and is used to specify
226 the most common epoch on Alphas with ARC console (but Ruffians
227 have epoch 1900).
228
229 --jensen
230
231 --funky-toy
232 These two options specify what kind of Alpha machine you have.
233 They are invalid if you don't have an Alpha and are usually
234 unnecessary if you do, because hwclock should be able to deter‐
235 mine by itself what it's running on, at least when /proc is
236 mounted. (If you find you need one of these options to make
237 hwclock work, contact the maintainer to see if the program can
238 be improved to detect your system automatically. Output of
239 `hwclock --debug' and `cat /proc/cpuinfo' may be of interest.)
240
241 Option --jensen means you are running on a Jensen model. And
242 --funky-toy means that on your machine one has to use the UF bit
243 instead of the UIP bit in the Hardware Clock to detect a time
244 transition. "Toy" in the option name refers to the Time Of Year
245 facility of the machine.
246
247
248
249 --test Do everything except actually updating the Hardware Clock or
250 anything else. This is useful, especially in conjunction with
251 --debug, in learning about hwclock.
252
253 --debug
254 Display a lot of information about what hwclock is doing inter‐
255 nally. Some of its function is complex and this output can help
256 you understand how the program works.
257
258
259
262 There are two main clocks in a Linux system:
263
264 The Hardware Clock: This is a clock that runs independently of any con‐
265 trol program running in the CPU and even when the machine is powered
266 off.
267
268 On an ISA system, this clock is specified as part of the ISA standard.
269 The control program can read or set this clock to a whole second, but
270 the control program can also detect the edges of the 1 second clock
271 ticks, so the clock actually has virtually infinite precision.
272
273 This clock is commonly called the hardware clock, the real time clock,
274 the RTC, the BIOS clock, and the CMOS clock. Hardware Clock, in its
275 capitalized form, was coined for use by hwclock because all of the
276 other names are inappropriate to the point of being misleading.
277
278 So for example, some non-ISA systems have a few real time clocks with
279 only one of them having its own power domain. A very low power exter‐
280 nal I2C or SPI clock chip might be used with a backup battery as the
281 hardware clock to initialize a more functional integrated real-time
282 clock which is used for most other purposes.
283
284 The System Time: This is the time kept by a clock inside the Linux ker‐
285 nel and driven by a timer interrupt. (On an ISA machine, the timer
286 interrupt is part of the ISA standard). It has meaning only while
287 Linux is running on the machine. The System Time is the number of sec‐
288 onds since 00:00:00 January 1, 1970 UTC (or more succinctly, the number
289 of seconds since 1969). The System Time is not an integer, though. It
290 has virtually infinite precision.
291
292 The System Time is the time that matters. The Hardware Clock's basic
293 purpose in a Linux system is to keep time when Linux is not running.
294 You initialize the System Time to the time from the Hardware Clock when
295 Linux starts up, and then never use the Hardware Clock again. Note
296 that in DOS, for which ISA was designed, the Hardware Clock is the only
297 real time clock.
298
299 It is important that the System Time not have any discontinuities such
300 as would happen if you used the date(1L) program to set it while the
301 system is running. You can, however, do whatever you want to the Hard‐
302 ware Clock while the system is running, and the next time Linux starts
303 up, it will do so with the adjusted time from the Hardware Clock.
304
305 A Linux kernel maintains a concept of a local timezone for the system.
306 But don't be misled -- almost nobody cares what timezone the kernel
307 thinks it is in. Instead, programs that care about the timezone (per‐
308 haps because they want to display a local time for you) almost always
309 use a more traditional method of determining the timezone: They use the
310 TZ environment variable and/or the /usr/share/zoneinfo directory, as
311 explained in the man page for tzset(3). However, some programs and
312 fringe parts of the Linux kernel such as filesystems use the kernel
313 timezone value. An example is the vfat filesystem. If the kernel
314 timezone value is wrong, the vfat filesystem will report and set the
315 wrong timestamps on files.
316
317 hwclock sets the kernel timezone to the value indicated by TZ and/or
318 /usr/share/zoneinfo when you set the System Time using the --hctosys
319 option.
320
321 The timezone value actually consists of two parts: 1) a field tz_min‐
322 uteswest indicating how many minutes local time (not adjusted for DST)
323 lags behind UTC, and 2) a field tz_dsttime indicating the type of Day‐
324 light Savings Time (DST) convention that is in effect in the locality
325 at the present time. This second field is not used under Linux and is
326 always zero. (See also settimeofday(2).)
327
328
330 Sometimes, you need to install hwclock setuid root. If you want users
331 other than the superuser to be able to display the clock value using
332 the direct ISA I/O method, install it setuid root. If you have the
333 /dev/rtc interface on your system or are on a non-ISA system, there's
334 probably no need for users to use the direct ISA I/O method, so don't
335 bother.
336
337 In any case, hwclock will not allow you to set anything unless you have
338 the superuser real uid. (This is restriction is not necessary if you
339 haven't installed setuid root, but it's there for now).
340
341
343 hwclock uses many different ways to get and set Hardware Clock values.
344 The most normal way is to do I/O to the device special file /dev/rtc,
345 which is presumed to be driven by the rtc device driver. However, this
346 method is not always available. For one thing, the rtc driver is a
347 relatively recent addition to Linux. Older systems don't have it.
348 Also, though there are versions of the rtc driver that work on DEC
349 Alphas, there appear to be plenty of Alphas on which the rtc driver
350 does not work (a common symptom is hwclock hanging). Moreover, recent
351 Linux systems have more generic support for RTCs, even systems that
352 have more than one, so you might need to override the default by speci‐
353 fying /dev/rtc0 or /dev/rtc1 instead.
354
355 On older systems, the method of accessing the Hardware Clock depends on
356 the system hardware.
357
358 On an ISA system, hwclock can directly access the "CMOS memory" regis‐
359 ters that constitute the clock, by doing I/O to Ports 0x70 and 0x71.
360 It does this with actual I/O instructions and consequently can only do
361 it if running with superuser effective userid. (In the case of a
362 Jensen Alpha, there is no way for hwclock to execute those I/O instruc‐
363 tions, and so it uses instead the /dev/port device special file, which
364 provides almost as low-level an interface to the I/O subsystem).
365
366 This is a really poor method of accessing the clock, for all the rea‐
367 sons that user space programs are generally not supposed to do direct
368 I/O and disable interrupts. Hwclock provides it because it is the only
369 method available on ISA and Alpha systems which don't have working rtc
370 device drivers available.
371
372
373 On an m68k system, hwclock can access the clock via the console driver,
374 via the device special file /dev/tty1.
375
376 hwclock tries to use /dev/rtc. If it is compiled for a kernel that
377 doesn't have that function or it is unable to open /dev/rtc (or the
378 alternative special file you've defined on the command line) hwclock
379 will fall back to another method, if available. On an ISA or Alpha
380 machine, you can force hwclock to use the direct manipulation of the
381 CMOS registers without even trying /dev/rtc by specifying the --direc‐
382 tisa option.
383
384
385
387 The Hardware Clock is usually not very accurate. However, much of its
388 inaccuracy is completely predictable - it gains or loses the same
389 amount of time every day. This is called systematic drift. hwclock's
390 "adjust" function lets you make systematic corrections to correct the
391 systematic drift.
392
393 It works like this: hwclock keeps a file, /etc/adjtime, that keeps some
394 historical information. This is called the adjtime file.
395
396 Suppose you start with no adjtime file. You issue a hwclock --set com‐
397 mand to set the Hardware Clock to the true current time. Hwclock cre‐
398 ates the adjtime file and records in it the current time as the last
399 time the clock was calibrated. 5 days later, the clock has gained 10
400 seconds, so you issue another hwclock --set command to set it back 10
401 seconds. Hwclock updates the adjtime file to show the current time as
402 the last time the clock was calibrated, and records 2 seconds per day
403 as the systematic drift rate. 24 hours go by, and then you issue a
404 hwclock --adjust command. Hwclock consults the adjtime file and sees
405 that the clock gains 2 seconds per day when left alone and that it has
406 been left alone for exactly one day. So it subtracts 2 seconds from
407 the Hardware Clock. It then records the current time as the last time
408 the clock was adjusted. Another 24 hours goes by and you issue another
409 hwclock --adjust. Hwclock does the same thing: subtracts 2 seconds and
410 updates the adjtime file with the current time as the last time the
411 clock was adjusted.
412
413 Every time you calibrate (set) the clock (using --set or --systohc),
414 hwclock recalculates the systematic drift rate based on how long it has
415 been since the last calibration, how long it has been since the last
416 adjustment, what drift rate was assumed in any intervening adjustments,
417 and the amount by which the clock is presently off.
418
419 A small amount of error creeps in any time hwclock sets the clock, so
420 it refrains from making an adjustment that would be less than 1 second.
421 Later on, when you request an adjustment again, the accumulated drift
422 will be more than a second and hwclock will do the adjustment then.
423
424 It is good to do a hwclock --adjust just before the hwclock --hctosys
425 at system startup time, and maybe periodically while the system is run‐
426 ning via cron.
427
428 The adjtime file, while named for its historical purpose of controlling
429 adjustments only, actually contains other information for use by
430 hwclock in remembering information from one invocation to the next.
431
432 The format of the adjtime file is, in ASCII:
433
434 Line 1: 3 numbers, separated by blanks: 1) systematic drift rate in
435 seconds per day, floating point decimal; 2) Resulting number of seconds
436 since 1969 UTC of most recent adjustment or calibration, decimal inte‐
437 ger; 3) zero (for compatibility with clock(8)) as a decimal integer.
438
439 Line 2: 1 number: Resulting number of seconds since 1969 UTC of most
440 recent calibration. Zero if there has been no calibration yet or it is
441 known that any previous calibration is moot (for example, because the
442 Hardware Clock has been found, since that calibration, not to contain a
443 valid time). This is a decimal integer.
444
445 Line 3: "UTC" or "LOCAL". Tells whether the Hardware Clock is set to
446 Coordinated Universal Time or local time. You can always override this
447 value with options on the hwclock command line.
448
449 You can use an adjtime file that was previously used with the clock(8)
450 program with hwclock.
451
452
453
455 You should be aware of another way that the Hardware Clock is kept syn‐
456 chronized in some systems. The Linux kernel has a mode wherein it
457 copies the System Time to the Hardware Clock every 11 minutes. This is
458 a good mode to use when you are using something sophisticated like ntp
459 to keep your System Time synchronized. (ntp is a way to keep your Sys‐
460 tem Time synchronized either to a time server somewhere on the network
461 or to a radio clock hooked up to your system. See RFC 1305).
462
463 This mode (we'll call it "11 minute mode") is off until something turns
464 it on. The ntp daemon xntpd is one thing that turns it on. You can
465 turn it off by running anything, including hwclock --hctosys, that sets
466 the System Time the old fashioned way.
467
468 If your system runs with 11 minute mode on, don't use hwclock --adjust
469 or hwclock --hctosys. You'll just make a mess. It is acceptable to
470 use a hwclock --hctosys at startup time to get a reasonable System Time
471 until your system is able to set the System Time from the external
472 source and start 11 minute mode.
473
474
475
477 There is some sort of standard that defines CMOS memory Byte 50 on an
478 ISA machine as an indicator of what century it is. hwclock does not
479 use or set that byte because there are some machines that don't define
480 the byte that way, and it really isn't necessary anyway, since the
481 year-of-century does a good job of implying which century it is.
482
483 If you have a bona fide use for a CMOS century byte, contact the
484 hwclock maintainer; an option may be appropriate.
485
486 Note that this section is only relevant when you are using the "direct
487 ISA" method of accessing the Hardware Clock. ACPI provides a standard
488 way to access century values, when they are supported by the hardware.
489
490
492 TZ
493
494
496 /etc/adjtime /usr/share/zoneinfo/ (/usr/lib/zoneinfo on old systems)
497 /dev/rtc /dev/rtc0 /dev/port /dev/tty1 /proc/cpuinfo
498
499
501 date(1), gettimeofday(2), settimeofday(2), crontab(1), tzset(3)
502
503
505 Written by Bryan Henderson, September 1996 (bryanh@giraffe-data.com),
506 based on work done on the clock program by Charles Hedrick, Rob Hooft,
507 and Harald Koenig. See the source code for complete history and cred‐
508 its.
509
510
512 The hwclock command is part of the util-linux package and is available
513 from ftp://ftp.kernel.org/pub/linux/utils/util-linux/.
514
515
516
517util-linux August 2011 HWCLOCK(8)