1 |
Mark Knecht posted |
2 |
<5bdc1c8b0602110941y446deb24qc519fcb40298136a@××××××××××.com>, excerpted |
3 |
below, on Sat, 11 Feb 2006 09:41:20 -0800: |
4 |
|
5 |
> Hello, |
6 |
> Just in the last week or so my AMD64 machine has started to exhibit |
7 |
> problems with the clock. Maybe it's a hardware problem, or possibly |
8 |
> it's some new ntpd issue after updates. At boot time it seems to be |
9 |
> coming up with semi-random times. This is causing me to ask a few |
10 |
> questions and try to learn a bit more about how this actually works |
11 |
> under Linux. Thanks in advance. |
12 |
|
13 |
Those can be quite frustrating. I'm not a master, but somehow, I've |
14 |
managed to bluster my way thru a couple frustrating episodes. |
15 |
|
16 |
> QUESTION 1: UTC vs. local |
17 |
> |
18 |
> In /etc/conf.d/clock I can choose UTC vs. local. Does this refer to |
19 |
> the time I set in the hardware clock or something else? Nominally it's |
20 |
> easier sitting here in California to set the hardware clock to |
21 |
> California time. Is there any problem with doing this? If I understand |
22 |
> the comments I should be using 'local' but the default seemed to be |
23 |
> UTC. |
24 |
|
25 |
UTC is effectively what used to be called GMT, Universal Time Coordinated |
26 |
(I believe French, so looks backward to us English folks), Greenwich Mean |
27 |
Time, the time standardized to London, UTC indicating as updated with |
28 |
official leap-seconds, according to kdict (just looked it up to be sure to |
29 |
get it right). |
30 |
|
31 |
The continental US is of course 5-8 hours behind UTC, with an adjustment |
32 |
for DST in the summer, naturally (that I thankfully don't have to worry |
33 |
about here in AZ). |
34 |
|
35 |
Traditionally, Unix has kept system time in UTC, while MSWormOS kept it in |
36 |
local time, so if you are booting between the two, it can /really/ screw |
37 |
things up. Modern Linux has a toggle, but if the toggle gets out of sync |
38 |
for some reason, you'll see it jumping back and forth by those several |
39 |
hours, as you boot and reset it and reboot. To get it synced back up can |
40 |
be more difficult than you'd expect, because if you don't do all the steps |
41 |
in the right order, it either doesn't take, or it takes, but just confirms |
42 |
the offset once again. |
43 |
|
44 |
> QUESTION 2: date |
45 |
> |
46 |
> date only sets a software clock, correct? Is this all the system uses |
47 |
> after boot? |
48 |
|
49 |
Short answer, yes, to both. The hardware clock only gets reset when you |
50 |
reset it, and it's not used for keeping time while the system is running. |
51 |
|
52 |
> QUESTION 3: hwclock -w |
53 |
> |
54 |
> This is supposed to write the time in the system's software clock into |
55 |
> hardware, correct? |
56 |
|
57 |
The key word there is /supposed/. Can you tell I've gotten rather |
58 |
frustrated with it? =8^P |
59 |
|
60 |
Here's a hint: It's /much/ easier to figure out how to use the Gentoo |
61 |
scripts and configuration, and call the initscript manually to reset the |
62 |
hardware clock if necessary, than it is to get the sequence of steps |
63 |
correct to set the hardware clock correctly, getting the toggle and the |
64 |
local time offset correct all at the same time. I don't know whether it's |
65 |
because the hwclock command line is unnecessarily obtuse, or what, but |
66 |
what one would /think/ would be a simple, logical process, just /isn't/! |
67 |
|
68 |
So. Set the Gentoo configuration, then turn off dhcpd if it's on and set |
69 |
the (system/software) clock, then issue the command /etc/init.d/clock |
70 |
restart, and it should first set the hardware clock from the software |
71 |
clock (as if its shutting down), then set the software clock from the |
72 |
hardware clock (as if the system is booting up). |
73 |
|
74 |
The settings you need, at least in the baselayout-1.12.0-pre series, are |
75 |
all in /etc/conf.d/clock. baselayout-1.11.x may have had a couple of |
76 |
these settings in either /etc/rc.conf or /etc/conf.d/rc, as I seem to |
77 |
remember some setting there, but they aren't there now. |
78 |
|
79 |
If you want to keep your hardware clock set for localtime, set |
80 |
CLOCK="local" in the config file. CLOCK_OPTS should normally remain |
81 |
blank. I'd certainly suggest you leave them so if this is at all useful |
82 |
to you, as I had little enough success setting the thing right manually |
83 |
that I wasn't /about/ to try and screw with things here, and if this is |
84 |
useful, than you know no more than I do about it! =8^P |
85 |
|
86 |
Perhaps the most important setting is CLOCK_SYSTOHC (system to hardware). |
87 |
You most likely want this set to "yes", as once you get things configured, |
88 |
ntpd will be keeping things adjusted for you and you'll be able to let it |
89 |
correct the hardware clock at shutdown. In any case, you'll probably want |
90 |
it set yes to allow you to properly set the hardware clock this time, then |
91 |
you can turn it back to no if you wish. |
92 |
|
93 |
Ensure the Alpha options are both set "no", as they should be unless you |
94 |
screwed with them desperately trying to get things to work. |
95 |
|
96 |
As I said above, once that's done, ensure dhcpd is off, and restart the |
97 |
clock system service (it'll probably warn you that your stopping a boot |
98 |
level service, but it shouldn't hurt, I do it here to set my clock). The |
99 |
clock boot script should then magically accomplish what was SO |
100 |
FRUSTRATINGLY DIFFICULT to get right, manually. |
101 |
|
102 |
Assuming there's nothing seriously wrong with your system, that should get |
103 |
things back to being relatively accurate. If it doesn't, there are a |
104 |
couple of possible causes. If the clock is going crazy, say running |
105 |
double-speed when the system is up, it's a system timer problem. You'll |
106 |
need to find some way to regulate your kernel so it keeps time properly, |
107 |
and dhcpd won't be able to help as the problem will be to drastic. The |
108 |
solution there involves possible kernel bootline switches, and/or finding |
109 |
the proper driver for your chipset so the kernel has a reliable hardware |
110 |
timer it can sync against. |
111 |
|
112 |
If your hardware clock keeps resetting to January 1 of 2000, or some other |
113 |
date, or if it goes random (not off by a fixed offset, which would |
114 |
indicate UTC/local issues again/still) it's possible you have a battery |
115 |
going dead, tho that really shouldn't be happening yet with amd64 boards. |
116 |
Maybe it was shorted out or something and lost a whole bunch of juice at |
117 |
once, or maybe you have a bad timing capacitor or something. This can be |
118 |
bad news, because it often indicates you are about to start having other |
119 |
problems, like the BIOS not retaining its settings over a shutdown, and |
120 |
the like. Get ready to buy a new mobo. However, if it's just the clock |
121 |
going bad, you can usually use ntp to correct the system once at boot and |
122 |
then keep things regular while running. It'll just be irritating if you |
123 |
boot up for maintenance and don't go online or start ntp as your time |
124 |
could be way off, but anyway... |
125 |
|
126 |
> QUESTION 4: |
127 |
> |
128 |
> Does ntpd actually update the system clock, or is it another layer yet |
129 |
> on top. If I use ntpd and then do hwclock -w does an accurate time get |
130 |
> written to the hardware clock? |
131 |
|
132 |
I don't like the term "system" clock in this context, because it's |
133 |
ambiguous as to whether you are referring to hardware or software. That's |
134 |
why I used system/software clock or the like a couple times above, to make |
135 |
it absolutely clear which I was referring to. |
136 |
|
137 |
That said, "system clock" normally refers to the software clock that the |
138 |
system uses while running, and yes, ntpd /does/ update it directly -- |
139 |
well, sort-of. <g> Don't worry, the confusion is normal and under the |
140 |
circumstances entirely understandable, but there's a logical explanation |
141 |
that makes sense once you understand what's going on. |
142 |
|
143 |
Here's the deal. ntpd was developed to be used in situations where |
144 |
various running programs might be making critical assumptions about the |
145 |
system time -- namely that it always moves forward, never backward. To |
146 |
have the time move backward, if the machine's an online server in some |
147 |
applications, would be /very/ /bad/! Thus, by default and if at all |
148 |
possible (if the time isn't off by days or years), ntpd will normally |
149 |
choose to /skew/ the time, adjusting how fast the machine advances time by |
150 |
a few parts per million, rather than stepping it either forward or |
151 |
backward by seconds/minutes/hours/days/whatever at a time. |
152 |
|
153 |
On Linux, the kernel is actually responsible for keeping time, and has a |
154 |
userland API that ntpd uses to skew the time, telling the kernel to |
155 |
measure say 999 998 instead of 1 000 000 ticks if the clock is slightly |
156 |
fast, until real time catches up, or 1 000 005 ticks instead of 1 000 000, |
157 |
if the clock is slightly slow and needs to catch up to real time. So, |
158 |
yes, ntpd /is/ adjusting the time, but ideally, not fast enough that |
159 |
anything can really notice it. |
160 |
|
161 |
Note also that ntpd keeps track of how far your system has drifted from |
162 |
the rest of the world, each time it checks in, and uses that to tweak |
163 |
system clock speed accordingly. If you go adjusting the clock yourself |
164 |
while ntpd is running, it's going to think something's drastically wrong |
165 |
with the system that it gained or lost so much time so fast, and will |
166 |
REALLY put the screws on that skew, thereby REALLY screwing up the system |
167 |
for a few days, as ntpd adjusts the clock first one way, then the other, |
168 |
until it figures out the real drift of the system once again. This is why |
169 |
I said turn off ntpd before you go screwing with the clock, even the |
170 |
little bit of setting the hardware clock from the software clock and then |
171 |
the software clock from the hardware clock, as you do by running |
172 |
/etc/init.d/clock restart, because even the 100th of a second leap that |
173 |
might happen setting the time between the two, would be enough to screw up |
174 |
ntpd's calculations and set your time swinging that much more than it |
175 |
should, for a day or two. Once it knows how accurate your system is on |
176 |
its own, ntpd can make it /really/ accurate, to single milliseconds within |
177 |
the day, but it can't do it if you keep screwing with the time yourself! |
178 |
ALWAYS turn ntpd off when you go screwing with the clock, for /whatever/ |
179 |
reason! |
180 |
|
181 |
FWIW, if you've been screwing with the clock enough to mix up ntpd and |
182 |
just want it to start over from scratch, shut it down (of course), and |
183 |
remove it's drift file, located by default on Gentoo at |
184 |
/var/lib/ntp/ntp.drift (I think, mine's in /etc/ntp/drift, as set in |
185 |
/etc/ntp.conf, but if the ntp.conf.orig I have here is correct, Gentoo's |
186 |
default is that /var location). |
187 |
|
188 |
OK, so what is used to do a time step, if ntpd normally does time skews? |
189 |
|
190 |
That's ntp-client. If you have ntp running on your system, you'll |
191 |
probably want both ntpd and ntp-client in your default runlevel. |
192 |
ntp-client runs before ntpd, and steps the clock to /approximately/ the |
193 |
correct time (within 100ms or so). It's a single-shot run at boot, after |
194 |
which ntpd starts, does it's connections to see how far it has to adjust, |
195 |
and gets to work doing the skew. If you look in the logs, probably 15 |
196 |
minutes to a couple hours later (assuming it has had time to get |
197 |
familiar with the system and how much it normally needs adjusted), it will |
198 |
say it's properly synced to its satisfaction, having skewed the system |
199 |
(software) clock by an appropriate degree, and then set out to maintain |
200 |
that sync over the longer term. |
201 |
|
202 |
Do note that there's an ntp-client config file in /etc/conf.d also, which |
203 |
you can use to tweak settings if desired. However, Gentoo's policy of |
204 |
setting things up so they "just work" if possible, is as usual in force |
205 |
here, and it should need no changes from you to work properly, once the |
206 |
initscript has been added to the proper runlevel, of course. |
207 |
|
208 |
Once you have it set up correctly, your system will boot and once the |
209 |
internet connection is up, ntp-client will start and do any "gross" |
210 |
adjustment necessary to the system time. After it's done, ntpd will run |
211 |
and keep your system very accurately synced with the rest of the world, |
212 |
timewise. When you shutdown, if you have clock configured to do so, it |
213 |
will sync the hardware clock to the software clock that ntpd has been |
214 |
managing so well while the system was up, keeping the hardware clock |
215 |
fairly accurate as well, even when you only boot to no-net single-user |
216 |
mode or whatever for system maintenance. |
217 |
|
218 |
One more thing to cover: If you suspend your system, you will want to |
219 |
ensure that ntpd is shut down before suspend, and ntp-client and ntpd are |
220 |
restarted after resume. Again, this ensures that ntpd is only tracking a |
221 |
running system, so doesn't get any strange and unnecessary jerks in its |
222 |
idea of how the system is keeping time, thereby keeping it as accurate as |
223 |
possible, which is the idea, after all! =8^) |
224 |
|
225 |
-- |
226 |
Duncan - List replies preferred. No HTML msgs. |
227 |
"Every nonfree program has a lord, a master -- |
228 |
and if you use the program, he is your master." Richard Stallman in |
229 |
http://www.linuxdevcenter.com/pub/a/linux/2004/12/22/rms_interview.html |
230 |
|
231 |
|
232 |
-- |
233 |
gentoo-amd64@g.o mailing list |