Monday, November 2, 2009

linux - timezone/time changes

Links:
Brief clock-setting example     Ntpd daemon documentation (in depth)
Clock processes on Red Hat     Clock processes in Archlinux

The Red Hat link describes time features functionally with some commands. The Archlinux link includes specific configuration file information.


Overview of clock/timezones in Slack/Zenwalk

The hardware clock, more technically the RTC (Real Time Clock), is the battery powered clock that sits on the motherboard. The software system clock grabs this when it boots. But many people want more accuracy and also run the ntpd daemon. After booting, NTPD periodically checks calibrated servers via the Web and makes corrections to the system clock. At shutdown, the system time is written to the hardware clock to keep it reasonably accurate as well. So, the chain of timekeeping goes something like this:

RTC -> System Clock (once,at boot) ->System Clock (corrected by NTPD) -> Timezone offset -> Desktop display

Singular to Zenwalk, I believe, is the file /etc/hardwareclock. An editable text file with one entry of either "localtime" or "UTC" (minus the quotes). I use 'UTC' (also known as GST or GMT): 1) UTC is the time served from the Web's ntp network time servers which means the system clock uses UTC, and 2) people traditionally know their timezone offsets against UTC, eg "My timezone is GMT -5", etc. Edit and save this file as administrator with any text editor such as geany or mousepad: # geany /etc/hardwareclock.

Hardware clock (RTC)
In any linux distribution, the command to view the hardware clock's time:
# hwclock

While I'm fussing around with time, the command for synchronizing the hardware clock with the NTP corrected system clock:
# hwclock --systohc

If for some reason one wanted to set the system time to the hardware clock (this is what happens at boot):
# hwclock --hctosys

System clock
Back to the story. The system clock periodically receives an accurate UTC/GST/GMT from ntpd . Settings are configured in /etc/ntp.conf and one can check operation with # service list. One can also force an update to the system clock. Turn off ntpd, (# service stop ntpd), to free the ntp port. Then, pick a time server, say one at ldsbc.edu, and :
# ntpdate ntp-nist.ldsbc.edu

To view the system clock, for example to verify an update:
$ date

Timezone offset
With a proper system time, one then wants the correct timezone offset in one's desktop/laptop time display. I currently have mine set to EST, but suppose I were to fly to Chicago, how do I set the timezone? Most of the answer is in /usr/share/zoneinfo.

The file /etc/localtime is supposed to be a soft ("sym")link pointing to the correct timezone in /usr/share/zoneinfo. In my system, there was a hard file in /etc/localtime instead of a symlink. Accordingly, to be sure, I removed both files and and created a new symlink to the correct timezone. For instance, since Chicago is CST, this would be the process when flying to Chicago:

# rm -r /etc/localtime
# rm -r /usr/share/zoneinfo/localtime
# ln -s /usr/share/zoneinfo/US/Central /etc/localtime

With these three commands, and setting /etc/hardwareclock to UTC, all should be good at the next reboot.

Sometimes a system is sticky even with this. If that's the case, do all of the above and also export the time variable $TZ, to the kernel. For example in PST regions:

$ export TZ=PST8PDT


A few ancillary notes
  • the directory /usr/share/zoneinfo contains the premade time zone options. It appears all potential time zones are in here.
  • the timezone file /etc/localtime appears filled with weird symbols like it's a bin file. It can't therefore be edited with a text editor.
  • the /usr/share/zoneinfo directory contains two soft links: localtime -> /etc/localtime, and timeconfig -> /usr/sbin/timeconfig. The symlink for /etc/localtime is explained above, but I'm uncertain why the timeconfig application would be linked here since it can easily be ran in any terminal.