View previous topic :: View next topic |
Author |
Message |
Verted Guru
Joined: 09 Apr 2004 Posts: 480 Location: London, England
|
Posted: Thu Mar 03, 2005 10:00 pm Post subject: Clock keeps losing sync |
|
|
I just reinstalled Linux. Prior to this my clock would keep nicely in sync with itself, but now it keeps getting lost. It loses about 5 minutes or more every day. Why would this be occuring? How can it be fixed? _________________ Thanks,
-Verted |
|
Back to top |
|
|
msalerno Veteran
Joined: 17 Dec 2002 Posts: 1338 Location: Sweating in South Florida
|
Posted: Thu Mar 03, 2005 10:11 pm Post subject: |
|
|
ntpdate ntp.nasa.gov
Possibly RTC support in the kernel? It's a long shot, but better than nothing.
2.4
If the kernel time is synchronized with an external source, the
kernel will write the time back to the CMOS clock every 11 minutes. In
the process of doing this, the kernel briefly turns off RTC periodic
interrupts, so be aware of this if you are doing serious work. If you
don't synchronize the kernel time with an external source (via ntp or
whatever) then the kernel will keep its hands off the RTC. |
|
Back to top |
|
|
Verted Guru
Joined: 09 Apr 2004 Posts: 480 Location: London, England
|
Posted: Thu Mar 03, 2005 10:44 pm Post subject: |
|
|
Wow that worked:)
Will it automatically update my time to the correct time? At say, boot, or when shutting the computer down? _________________ Thanks,
-Verted |
|
Back to top |
|
|
msalerno Veteran
Joined: 17 Dec 2002 Posts: 1338 Location: Sweating in South Florida
|
Posted: Thu Mar 03, 2005 10:52 pm Post subject: |
|
|
You could set a cron job to run the ntpdate command every 8 or so hours. You can find a list of nearby ntp servers through google. |
|
Back to top |
|
|
piffle Tux's lil' helper
Joined: 14 Jun 2004 Posts: 98
|
Posted: Fri Mar 04, 2005 3:38 am Post subject: |
|
|
On my laptop I had to add "clock=tsc" to by boot line in grub to stop it from losing 15-20 minutes a day. Running ntpdate from a cron job is roundly discouraged, from what I have read online (you will end up with big, periodic clock adjustments, which can cofuse some applications). The best solution is to get the ntp daemon running so that your clock is continuously kept in sync with precise timeservers. However, even ntp will not work if your clock is really running out of control, so try to get a fix for that first. |
|
Back to top |
|
|
transient l33t
Joined: 13 Jan 2005 Posts: 759
|
Posted: Fri Mar 04, 2005 5:06 am Post subject: |
|
|
Do not use a cron job to sync your time. It will get massivly out-of-sync.
Use ntpd to do it, this is what its for, and it does a far better job at it:
Delete the default /etc/ntp.conf and create a new one with these lines in it:
Code: |
driftfile /var/lib/ntp/ntp.drift
server 0.<yourcountrycode>.pool.ntp.org
server 1.<yourcountrycode>.pool.ntp.org
server 2.<yourcountrycode>.pool.ntp.org
restrict default nomodify nopeer
restrict 127.0.0.1
|
Replace <yourcountrycode> with whatever your country's code is, obviously
Mine is "nz" as Im in New Zealand.
Then open /etc/conf.d/ntp-client and change the following settings in it:
Code: |
NTPCLIENT_CMD="ntpd"
NTPCLIENT_OPTS="-q"
NTPCLIENT_TIMEOUT=30
|
Then simply do the following:
Code: | rc-update add ntpd default
rc-update add ntp-client default
/etc/init.d/ntp-client start
/etc/init.d/ntpd start
|
This will keep your clock permanently set correct |
|
Back to top |
|
|
msalerno Veteran
Joined: 17 Dec 2002 Posts: 1338 Location: Sweating in South Florida
|
Posted: Fri Mar 04, 2005 2:43 pm Post subject: |
|
|
Nice |
|
Back to top |
|
|
Verted Guru
Joined: 09 Apr 2004 Posts: 480 Location: London, England
|
Posted: Fri Mar 04, 2005 4:35 pm Post subject: |
|
|
That looks good, but I think i've done something wrong:
Code: | verted root # /etc/init.d/ntp-client start
* Setting clock via the NTP client 'ntpd'...
usage: ntpd [ -abdgmnqx ] [ -c config_file ] [ -e e_delay ]
[ -f freq_file ] [ -k key_file ] [ -l log_file ]
[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]
[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]
[ -P fixed_process_priority ]
[ -u user[:group] ] [ -i chrootdir ]
* Failed to set clock |
Any idea what it is? _________________ Thanks,
-Verted |
|
Back to top |
|
|
BioSLuDge Tux's lil' helper
Joined: 12 Jul 2004 Posts: 99 Location: Utah
|
Posted: Fri Mar 04, 2005 10:10 pm Post subject: |
|
|
I saw this post and have been having problems with my clock so I took transient's advice and I emerged and setup ntpd and ntpd client. The problem is, every time I run the ntp-client. The ntpd.log shows the fallows.
Code: |
4 Mar 15:05:25 ntpd[30429]: sendto(64.112.189.11): Bad file descriptor
4 Mar 15:05:26 ntpd[30429]: sendto(198.60.22.240): Bad file descriptor
4 Mar 15:05:27 ntpd[30429]: sendto(64.112.189.11): Bad file descriptor
4 Mar 15:05:28 ntpd[30429]: sendto(198.60.22.240): Bad file descriptor
4 Mar 15:05:29 ntpd[30429]: sendto(64.112.189.11): Bad file descriptor
4 Mar 15:05:30 ntpd[30429]: sendto(198.60.22.240): Bad file descriptor
4 Mar 15:05:31 ntpd[30429]: sendto(64.112.189.11): Bad file descriptor
4 Mar 15:05:32 ntpd[30429]: sendto(198.60.22.240): Bad file descriptor
4 Mar 15:05:33 ntpd[30429]: sendto(64.112.189.11): Bad file descriptor
4 Mar 15:05:35 ntpd[30429]: no reply; clock not set
|
my /etc/ntp.conf file is
Code: |
logfile /var/log/ntpd.log
driftfile /var/lib/ntp/ntp.drift
restrict default nomodify nopeer
restrict 127.0.0.1
server time.xmission.com
server us.pool.ntp.org
|
and my client is configured exactly as explained above.
I have searched and searched for this problem, for the most part I found that its an issue with restrict. But I have removed the restrict options and I still get the error.
Thank you for your time in advanced
-BioSLuDge |
|
Back to top |
|
|
transient l33t
Joined: 13 Jan 2005 Posts: 759
|
Posted: Fri Mar 04, 2005 11:21 pm Post subject: |
|
|
Make sure that you havnt started ntpd before ntp-client.
They both attempt to bind to the same socket, so if ntpd starts up, ntp-client wont be able to connect and set the time.
The idea behind ntp-client is that it is a one-off command. It runs once at bootup, sets your clock, and exits.
Ntpd on the other hand is meant to continue running while your computer is on. It will periodically update your clock.
You need to make sure that ntpd starts after ntp-client has started. |
|
Back to top |
|
|
sysnine n00b
Joined: 04 Mar 2005 Posts: 17
|
Posted: Fri Mar 04, 2005 11:30 pm Post subject: |
|
|
sometimes this is the result of a failing CMOS battery. just some food for thought for others that come to this thread in the future. i had that problem, also, right after a fresh installation. why would the damned thing treat your new install with any respect? hehe. good luck all _________________ Libra: today is a good day to make important life decisions based on arbitrary nonsense written by an anonymous stranger in a newspaper. |
|
Back to top |
|
|
BioSLuDge Tux's lil' helper
Joined: 12 Jul 2004 Posts: 99 Location: Utah
|
Posted: Sat Mar 05, 2005 2:06 am Post subject: |
|
|
Ok, that was probably the problem. The ntpd is working tho, I have seen the log file from it and it seams to be running well. Sorry for the n00b question and thanks for your help.
Thanks again
-BioSLuDge |
|
Back to top |
|
|
Verted Guru
Joined: 09 Apr 2004 Posts: 480 Location: London, England
|
Posted: Sat Mar 05, 2005 11:03 am Post subject: |
|
|
Mine doesnt work. It's because of the error I stated above. I think it's because of this file, but I dont know much about it so I cant correct it.
Code: | # Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/net-misc/ntp/files/ntp-client.confd,v 1.10 2005/01/28 22:37:09 vapier Exp $
# Command to run to set the clock initially
# Most people should just leave this line alone ...
# however, if you know what you're doing, and you
# want to use ntpd to set the clock, change this to 'ntpd'
NTPCLIENT_CMD="ntpd"
# Options to pass to the above command
# This default setting should work fine but you should
# change the default 'pool.ntp.org' to something closer
# to your machine. See http://www.pool.ntp.org/ or
# try running `netselect -s 3 pool.ntp.org`.
NTPCLIENT_OPTS="-q pool.ntp.org"
# How long to wait (in seconds) before giving up.
# Useful for when you boot and DNS/internet isn't
# really available but you have your net interface
# come up with say a static IP.
NTPCLIENT_TIMEOUT=30
|
Anything wrong with that? _________________ Thanks,
-Verted |
|
Back to top |
|
|
Verted Guru
Joined: 09 Apr 2004 Posts: 480 Location: London, England
|
Posted: Tue Mar 08, 2005 8:30 pm Post subject: |
|
|
Still isnt working. I get this message:
Code: | verted root # /etc/init.d/ntp-client restart
* Setting clock via the NTP client 'ntpd'...
usage: ntpd [ -abdgmnqx ] [ -c config_file ] [ -e e_delay ]
[ -f freq_file ] [ -k key_file ] [ -l log_file ]
[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]
[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]
[ -P fixed_process_priority ]
[ -u user[:group] ] [ -i chrootdir ]
* Failed to set clock |
Anyone know how to fix it?
Also, about the CMOS battery. It seems likely that this is my problem (even though the motherboard is only about 7 months old). Is it possibly to buy replacements? _________________ Thanks,
-Verted |
|
Back to top |
|
|
transient l33t
Joined: 13 Jan 2005 Posts: 759
|
Posted: Tue Mar 08, 2005 10:58 pm Post subject: |
|
|
Remove the server from your NTPCLIENT_OPTS line.
It should just have -q in it. |
|
Back to top |
|
|
Verted Guru
Joined: 09 Apr 2004 Posts: 480 Location: London, England
|
Posted: Tue Mar 08, 2005 11:26 pm Post subject: |
|
|
Hmm. I still get an error:
Code: | verted root # /etc/init.d/ntp-client restart
* Setting clock via the NTP client 'ntpd'...
/sbin/runscript.sh: line 532: 13628 Killed ${NTPCLIENT_CMD} ${NTPCLIENT_OPTS} >/dev/null
* Failed to set clock |
This is how my NTPCLIENT_OPTS looks now:
Code: | # Options to pass to the above command
# This default setting should work fine but you should
# change the default 'pool.ntp.org' to something closer
# to your machine. See http://www.pool.ntp.org/ or
# try running `netselect -s 3 pool.ntp.org`.
NTPCLIENT_OPTS="-q"
|
It's a different error though. Any idea how this can be fixed? _________________ Thanks,
-Verted |
|
Back to top |
|
|
Verted Guru
Joined: 09 Apr 2004 Posts: 480 Location: London, England
|
Posted: Wed Mar 09, 2005 6:58 pm Post subject: |
|
|
Any ideas? (See above). _________________ Thanks,
-Verted |
|
Back to top |
|
|
transient l33t
Joined: 13 Jan 2005 Posts: 759
|
Posted: Wed Mar 09, 2005 10:14 pm Post subject: |
|
|
Have you setup your /etc/ntp.conf properly?
The ntp-client config looks fine, so the only thing I can think of is something in ntp.conf |
|
Back to top |
|
|
Verted Guru
Joined: 09 Apr 2004 Posts: 480 Location: London, England
|
Posted: Wed Mar 09, 2005 11:36 pm Post subject: |
|
|
Is this ok?
Code: | restrict default noquery notrust nomodify
restrict 127.0.0.1
restrict 82.43.160.0 mask 255.255.248.0
fudge 127.127.1.0 stratum 3
server 127.127.1.0
driftfile /var/lib/ntp/ntp.drift
logfile /var/log/ntp.log
|
_________________ Thanks,
-Verted |
|
Back to top |
|
|
transient l33t
Joined: 13 Jan 2005 Posts: 759
|
Posted: Thu Mar 10, 2005 12:50 am Post subject: |
|
|
It looks fine.
Hmm...
you could check the permissions of the /var/lib/ntp/ntp.drift file, and make sure that its got ownership of ntp:ntp and permissions of 0644. |
|
Back to top |
|
|
Verted Guru
Joined: 09 Apr 2004 Posts: 480 Location: London, England
|
Posted: Thu Mar 10, 2005 7:36 pm Post subject: |
|
|
Yep. That's all correct. I wonder why mine wont work>_< _________________ Thanks,
-Verted |
|
Back to top |
|
|
schachti Advocate
Joined: 28 Jul 2003 Posts: 3765 Location: Gifhorn, Germany
|
Posted: Tue Apr 12, 2005 8:11 am Post subject: |
|
|
transient wrote: |
Remove the server from your NTPCLIENT_OPTS line.
It should just have -q in it.
|
Hmm, the man page auf ntpdate says:
Code: |
-q Query only - don't set the clock.
|
And as ntp-client calls ntpdate (NTPCLIENT_CMD="ntpdate"), that might not be what you want, or am I wrong? _________________ Never argue with an idiot. He brings you down to his level, then beats you with experience.
How-To: Daten verschlüsselt auf DVD speichern. |
|
Back to top |
|
|
Stuart_Gilbert n00b
Joined: 08 Sep 2003 Posts: 66
|
Posted: Wed Apr 13, 2005 5:04 am Post subject: |
|
|
schachti wrote: | And as ntp-client calls ntpdate (NTPCLIENT_CMD="ntpdate"), that might not be what you want, or am I wrong? |
ntpdate isn't what's being called. it's ntpd, and the q option for that simply makes it exit after running once:
Code: | -q Exit the ntpd just after the first time the clock is set. This behavior mimics that of the ntp-
date program, which is to be retired. The -g and -x options can be used with this option. Note:
The kernel time discipline is disabled with this option.
|
Anyway, I've been having the exact same problem as Verted. I've got the same conf files and the same error.
A possible solution...
I was looking through the output of dmesg before and I was noticing a message about TSC not being a valid timesource or whatever. It suggested that DMA might be the cause. I've had problems with enabling DMA before, and thanks to this post I managed to add the correct chipset support to my kernel and enable DMA...
Once I'd turned DMA on using `hdparm -d1` I could apparently run
Code: | /etc/init.d/ntpd start
/etc/init.d/ntp-client start |
without encountering any errors. Unfortunately I forgot to actually check if my clock was out to begin with... and I'm not compiling at the moment so I can't check it very easily... but this is certainly a possible solution that seems to have worked for me.
I'll edit my post accordingly in the morning if I'm completely and utterly wrong.
Edit
Besides the fact that I still need to sort out my wireless networking it all seems fine.
The networking problems prevent time updates from running correctly on boot for me, but once everything's up and running ntpd seems to do it's thing. The following is with Mozilla compiling and the conf files provided in the above post.
Code: | Apr 12 22:08:09 marvin ntpd[8057]: kernel time sync status 0040
Apr 12 22:08:09 marvin ntpd[8057]: frequency initialized 0.000 PPM from /var/lib/ntp/ntp.drift
Apr 12 22:10:01 marvin /usr/sbin/cron[11507]: (root) CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-crons )
Apr 12 22:11:03 marvin su(pam_unix)[18077]: session opened for user root by stu(uid=1000)
Apr 12 22:16:44 marvin ntpd[8057]: synchronized to 64.142.114.146, stratum=2
Apr 12 22:16:44 marvin ntpd[8057]: kernel time sync disabled 0041
Apr 12 22:20:01 marvin /usr/sbin/cron[28808]: (root) CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-crons )
Apr 12 22:29:35 marvin ntpd[8057]: kernel time sync enabled 0001
Apr 12 22:29:37 marvin ntpd[8057]: time reset +0.174397 s
Apr 12 22:30:01 marvin /usr/sbin/cron[31252]: (root) CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-crons ) |
Looks good to me. Check DMA |
|
Back to top |
|
|
schachti Advocate
Joined: 28 Jul 2003 Posts: 3765 Location: Gifhorn, Germany
|
Posted: Wed Apr 13, 2005 1:41 pm Post subject: |
|
|
Stuart_Gilbert wrote: |
schachti wrote: | And as ntp-client calls ntpdate (NTPCLIENT_CMD="ntpdate"), that might not be what you want, or am I wrong? |
ntpdate isn't what's being called. it's ntpd, and the q option for that simply makes it exit after running once:
|
Why do you think that it does call ntpd instead of ntp-date?
/etc/init.d/ntp-client calls NTPCLIENT_CMD:
Code: |
[...]
start() {
[...]
${NTPCLIENT_CMD} ${NTPCLIENT_OPTS} >/dev/null &
|
And in /etc/conf.d/ntp-client, the default value for NTPCLIENT_CMD is
Code: |
# Command to run to set the clock initially
# Most people should just leave this line alone ...
# however, if you know what you're doing, and you
# want to use ntpd to set the clock, change this to 'ntpd'
NTPCLIENT_CMD="ntpdate"
|
(This is the default configuration of net-misc/ntp-4.2.0-r2). _________________ Never argue with an idiot. He brings you down to his level, then beats you with experience.
How-To: Daten verschlüsselt auf DVD speichern. |
|
Back to top |
|
|
Stuart_Gilbert n00b
Joined: 08 Sep 2003 Posts: 66
|
Posted: Wed Apr 13, 2005 3:26 pm Post subject: |
|
|
schachti wrote: | Why do you think that it does call ntpd instead of ntp-date? |
Because that's what it says to do in the configuration file that's being used by the person who posted the message with the error.
Verted is using the configuration file that transient posted:
verted wrote: | Mine doesnt work. It's because of the error I stated above. I think it's because of this file, but I dont know much about it so I cant correct it.
# Command to run to set the clock initially
# Most people should just leave this line alone ...
# however, if you know what you're doing, and you
# want to use ntpd to set the clock, change this to 'ntpd'
NTPCLIENT_CMD="ntpd" |
verted wrote: | Still isnt working. I get this message:
verted root # /etc/init.d/ntp-client restart
* Setting clock via the NTP client 'ntpd'...
usage: ntpd [ -abdgmnqx ] [ -c config_file ] [ -e e_delay ]
[ -f freq_file ] [ -k key_file ] [ -l log_file ]
[ -p pid_file ] [ -r broad_delay ] [ -s statdir ]
[ -t trust_key ] [ -v sys_var ] [ -V default_sysvar ]
[ -P fixed_process_priority ]
[ -u user[:group] ] [ -i chrootdir ]
* Failed to set clock
Anyone know how to fix it? |
transient wrote: | Remove the server from your NTPCLIENT_OPTS line.
It should just have -q in it. |
and that error goes away. |
|
Back to top |
|
|
|