hardware clock, HW clock, real-time clock, RTC, RT clock, BIOS clock, CMOS clock: This is a battery-powered clock on that runs even when the computer is turned off or unpowered. It is usually quite inaccurate. It is normally only used to initialize the "OS clock" during bootup. However, software is available which can sync the OS clock to an external source (via a network or HW port) and this software can usually update the HW clock occasionally. Also, the HW clock can be made to provide interrupts at various frequencies for custom timing needs.
software clock, SW clock, system clock, OS clock: This is simply a timer-interrupt-driven software counter. The kernel controls this clock and keeps several related numbers that may be viewed and changed with the "adjtimex" (or other programs like "xntpd"). The numbers include a drift estimate which can be used to reduce the OS clock drift.
UTC: Universal Time, Coordinated. Almost the same as GMT. Most of the Internet runs on UTC. The theory link below [now broken] has much more info.
A basic method to set the system and hardware clocks:
date ## to see current Unix time
clock -r ## to see current CMOS time
date -s TIME ## to set system clock, where TIME is "13:44:30" or output of "date" or similar
clock -w -u ## to set hardware clock to UTC time from system clock in local time.
A alternate version of the same:
date ## to see current Unix time
hwclock --show ## to see current CMOS time
date -s TIME ## to set system clock, where TIME is "13:44:30" or output of "date" or similar
hwclock --systohc --utc ## to set hardware clock to UTC time from system clock in local time.
An advanced method (my brief untested summary):
To get your clocks running well, do the following (assuming use of local
time, not utc). It also assumes that no programs are running that will
be confused by change of the OS clock.
-- Ensure that your startup scripts do two things:
-- Adjust the HW clock for drift (hwclock --adjust)
-- Set the OS clock to the HW clock (hwclock --hctosys)
-- Initialize the /etc/adjtime file and clocks thusly
(or use a program like xntpd for several hours):
-- Remove the /etc/adjtime file.
-- Set the HW clock (hwclock --set --date="[date string]") which
initializes the /etc/adjtime file.
-- Set the OS clock (hwclock --hctosys)
-- After several days, reset the clocks:
-- (hwclock --set --date="[date string]") which changes
/etc/adjtime so the HW clock drift rate is saved.
-- Use the adjtimex command (see man page) to adjust the
OS clock time and drift rate parameters.
-- Repeat as needed to correct drifts.
From Usenet: In my ip-up script I have # Synchronizing time with NTP-server # next line updates the OS-time /usr/local/bin/ntpdate -u ntp0.nl.net >> /var/adm/messages /bin/date >> /var/adm/messages /usr/bin/sleep 1 # next line updates the hardware-clock /sbin/clock -w /usr/bin/sleep 1 # End synchronizing Works flawlessly!