Ict-innovation/LPI/107.3

= 107.3 Localization and Internationalization = ''Candidates should be able to localize a system in a different language than English. As well, an understanding of why LANG=C is useful when scripting.''

Key Knowledge Areas


 * Locale settings.
 * Timezone settings.

Time is very important on the Linux System. Many facilities such as Anacron, Crontab, Backup, Restore, Update Managers all need accurate time to be able to perform their executions well. Developments in computing have resulted in computer systems that are able to keep time even when the computer is switched off.

There are 2 kinds of clocks on the Linux system;

Hardware Clock aka RTC, RealTimeClock, CMOS Clock, BIOS Clock. This clock runs independent of the Operating System and runs even when the computer is turned OFF, as long as the CMOS battery lasts.

Software Clock aka System Clock. This clock runs via the system timer interrupt. Normally, it will count the number of seconds since 1st Jan 1970. Is the main clock under Linux. At boot time it reads the hardware clock and continues alone from there.

Under Linux 2 main programs are used to control the 2 clocks. The hardware clock can be directly changed with the hwclock utility. The main options are:

-r or –-show prints the current times

-w or –-systohc set the hardware clock to the current system time

-s or –-hctosys set the system time to the current hardware clock time

The System Clock is controlled by the date facility. It can also be used to show the System time.

Syntax: date [options]

Options include: +text_and_metacodes

To display System time, using the date utility, you can issue a command like:

date "+It is now %H Hours and %M Minutes"

Will have the following result: It is now 14 Hours and 33 Minutes

Setting the Time and Date in Linux

You can set the time using 2 relatively simple procedures:

1) Set the Hardware clock to UTC via the BIOS setup.

2) Set the environment variable TZ to the proper time zone using the script: tzselect

The System date on the other hand can be changed with the date command. The syntax is:

date MMDDhhmmCCYY[.ss]

Note:In the file /etc/adjtime the correction factor can be saved to keep the clock as accurate as possible.

Time Zone Configuration

The time zone is a simply a measure of the difference of your local time from UTC. The /usr/share/zoneinfo file will store information on all available time zones. On many modern systems, this file the /usr/share filesystem needs to be mounted when the local time zone information is needed early in the boot process.

Some countries, in addition to UCT (used interchangeably with UTC) time, apply “day light saving”, a phenomenon where clocks are moved an hour ahead or behind at a specific date every year. Such policies are available on a Linux system in /usr/share/zoneinfo/. As long as the appropriate zone file is copied to /etc/localtime, a user can ensure that Time Zone's policies are in effect. 

For example if we copy /usr/share/zoneinfo/Nairobi to /etc/localtime the next time we run date this will give us the time in Nairobi. This is because date will read /etc/localtime each time it is run.

Setting System time with tzconfig

You can use the tzconfig utility to modify your time zone.

Using NTP

NTP stands for Network Time Protocol. It is defined in RFC1305 to provide for the transfer and maintenance of time functions over multiple network systems. One of the commonest NTP servers in use is ntpd (ntp.isc.org) It works by correcting with delicate accuracy, any differences of the system clock, as opposed to large adjustments at once or within very few hours.

The computer synchronizes its time by sending messages to the time server. The time returned is adjusted by an offset of half the round-trip delay. As a result, the accuracy of the time is therefore dependent on the network latency in both directions. Faster networks (the shorter the path to a time server), are likely to have a more accurate time.

Graphically, you should be able to set your NTP time servers using a dialog similar to that in the figure below.



''Figure 107.3-2. Setting NTP servers''

NTP configurations are kept in /etc/ntp.conf, but the ntpd daemon has to be restarted after you save any changes to the configuration file.

Configuring a client to query an NTP server:

An NTP daemon called ntpd is used to regularly query a remote time server. All that is needed is a server entry in /etc/ntp.conf </tt>pointing to a public or corporate NTP server. Public NTP servers can be found online.

The NTP protocol can also estimate the frequency errors of the hardware clock from a sequence of queries, this estimate is written to a file referred to by the driftfile tag.

NTP Commands

The ntpdate </tt>command can be used to set system time from an NTP time server as shown below

========================================================================================

NTP servers run in round robin mode, so its possible that the next time you run ntpdate, a different server will be queried. The pool from which a server is selected can be viewed when u dig your DNS, as shown below.

Round robin NTP server pool

The ntpdate </tt>command can be effected using ntpd</tt> with the -q </tt>option, as shown below.

Setting system time using ntpd -q</tt>

Note: ntpd </tt>command uses the time server information from /etc/ntp.conf. If the ntpd </tt>daemon is running,ntpd-q </tt>will quietly exit, leaving a failure message in /var/log/messages.The NTP daemon itself can be queired using the ntpq </tt>command.

The following is a partial list of the files, terms and utilities that were used


 * /etc/timezone
 * /etc/localtime
 * /usr/share/zoneinfo
 * Environment variables:
 * LC_*
 * LC_ALL
 * LANG
 * /usr/bin/locale
 * tzselect
 * tzconfig
 * date
 * iconv
 * UTF-8
 * ISO-8859
 * ASCII
 * Unicode

Previous Chapter | Next Chapter