Wednesday, June 06, 2007

Fixing Clock Drift On Gentoo

(Link to the original post)
Recently a machine I set up with Gentoo linux started having its hardware clock drift quite wildly. In the morning it could be up to half an hour out. This was caused by a severe skew with the hardware clock and the system clock (or the BIOS clock and linux clock respectively). So to fix this I did two things, 1 install ntpd and 2 fix the hwclock.

Installing ntpd was quite easy:

# emerge net-misc/ntp
# nano -w /etc/conf.d/ntpd

Fill in the server you want, you can use the links specified for a list of servers.

# /etc/init.d/ntpd start

If no errors are reported go on, else see if something silly has happened (e.g. typo in /etc/conf.d/ntpd).

# rc-update add ntpd default

Next I fixed adjtime and set the h/w clock correctly:

# rm /etc/adjtime
# date MMDDhhmm[[CC]YY][.ss]

(e.g. date 100912002002 for 12:00pm 10/9/2002)

Finally I set the h/w clock with the system time.

#hwclock --utc --systohc

Comments

Ruben

I tried this but it's not working can you tell me if this will work if my /etc/localtime links to /etc/zoneinfo/US/Central or do I have to change that too

Curtis

By the way, to avoid clock conflicts if your machine is a dual-boot with Window$, you should set your hwclock to local, not utc. So the last command in your tutorial here should be:

#hwclock --local --systohc

Michael Twomey

Wow, never noticed these comments, darn.

Ruben - no, the time zone should have no impact

Curtis - this is true if you dual boot. However I recommend using UTC if you aren't dual booting, as it solves a few nasty problems when daylight savings time changes.