Home Blog Certs Knowledge Base About

LPIC-1 108.1 โ€” Maintain System Time

Exam weight: 3 โ€” LPIC-1 v5, Exam 102

What You Need to Know

From the official LPIC-1 objectives:

  • Set the system date and time.
  • Set the hardware clock to the correct time in UTC.
  • Configure the correct timezone.
  • Basic NTP configuration using ntpd and chrony.
  • Knowledge of the pool.ntp.org service.
  • Awareness of the ntpq, chronyc, and timedatectl commands.

Key files and commands: /usr/share/zoneinfo/, /etc/timezone, /etc/localtime, /etc/ntp.conf, /etc/chrony.conf, date, hwclock, timedatectl, ntpd, ntpq, chronyd, chronyc, pool.ntp.org.


System Clock vs Hardware Clock

Linux maintains two separate clocks:

ClockDescription
System clockSoftware clock maintained by the kernel; lost on power-off
Hardware clock (RTC)Battery-backed clock on the motherboard; persists without power

At boot, the kernel reads the RTC to initialize the system clock. After that, the two clocks run independently.

The hardware clock can store time as local time or UTC. Linux distributions default to UTC for the hardware clock, which avoids complications from daylight saving time changes.


date โ€” System Clock

date displays or sets the system clock.

$ date
Mon Oct 21 10:45:21 -03 2019

Useful date Options

OptionDescription
-uDisplay or set time in UTC
-IOutput in ISO 8601 format (YYYY-MM-DD)
-ROutput in RFC 2822 format (used in email headers)
+%sOutput Unix epoch (seconds since 1970-01-01 00:00:00 UTC)
--date=@EPOCHConvert epoch to human-readable date
--debugShow details about how the date string was parsed
-s "STRING"Set the system clock to the given time string
$ date -u
Mon Oct 21 13:45:21 UTC 2019

$ date +%s
1571661921

$ date --date=@1571661921
Mon Oct 21 10:45:21 -03 2019

$ date -s "2019-10-21 10:45:00"

hwclock โ€” Hardware Clock

hwclock reads or sets the hardware (RTC) clock and can synchronize it with the system clock.

OptionDescription
--systohcSet hardware clock from system clock
--hctosysSet system clock from hardware clock
--set --date="STRING"Set hardware clock to the given date/time
--verboseShow detailed output
# Read hardware clock
$ hwclock

# Sync hardware clock to match system clock
$ hwclock --systohc

# Set hardware clock directly
$ hwclock --set --date="2019-10-21 10:45:00"

timedatectl โ€” systemd Time Management

timedatectl is the systemd tool for viewing and configuring time, timezone, and NTP sync.

$ timedatectl
               Local time: Mon 2019-10-21 10:45:21 -03
           Universal time: Mon 2019-10-21 13:45:21 UTC
                 RTC time: Mon 2019-10-21 13:45:21
                Time zone: America/Sao_Paulo (-03, -0300)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

timedatectl Commands

CommandDescription
timedatectl set-time "YYYY-MM-DD HH:MM:SS"Set system time (NTP must be off)
timedatectl list-timezonesList all available time zones
timedatectl set-timezone ZONESet the system time zone
timedatectl set-ntp true/falseEnable or disable NTP synchronization
timedatectl show-timesync --allShow full NTP sync details (systemd-timesyncd)

NTP Concepts

NTP (Network Time Protocol) synchronizes clocks across a network. Servers are organized into a hierarchy called strata:

  • Stratum 0: Reference clocks (atomic clocks, GPS receivers) โ€” not on the network directly
  • Stratum 1: Servers directly connected to stratum 0 sources
  • Stratum 2: Servers synchronized from stratum 1
  • Higher strata introduce more potential error

pool.ntp.org provides a pool of public NTP servers, distributing load across many hosts.

NTP Terms

TermDescription
OffsetDifference between local clock and NTP time
StepImmediate large time adjustment (when offset is large)
SlewGradual clock speed adjustment to reduce offset over time
Insane TimeOffset too large to correct safely (default threshold: 1000 seconds in ntpd)
DriftSystematic rate at which a clock gains or loses time
JitterVariability/instability in offset measurements

systemd-timesyncd

systemd-timesyncd is a lightweight SNTP client included with systemd. It is simpler than ntpd or chrony and suitable for most desktop and server use cases that do not need to serve time.

Configuration is in /etc/systemd/timesyncd.conf. Status is shown by timedatectl show-timesync --all.


ntpd โ€” NTP Daemon

ntpd (from the ntp package) is the classic full NTP implementation โ€” it can both synchronize from upstream servers and serve time to other hosts.

Configuration file: /etc/ntp.conf

Typical /etc/ntp.conf:

server 0.pool.ntp.org iburst
server 1.pool.ntp.org iburst
server 2.pool.ntp.org iburst
driftfile /var/lib/ntp/ntp.drift

The iburst option sends several packets at startup to synchronize quickly.

ntpq -p โ€” Peer Status

ntpq -p shows the list of NTP peers and their status:

     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*0.pool.ntp.org  10.0.0.1        2 u   15   64  377    1.234   -0.456   0.123
ColumnMeaning
remoteNTP server hostname (prefix: * = selected, + = acceptable, - = discarded)
refidReference ID of the server’s time source
stStratum of the remote server
whenSeconds since last packet received
pollPolling interval in seconds
reachOctal bitmask of last 8 poll successes (377 = all succeeded)
delayRound-trip delay to the server (ms)
offsetTime difference between local clock and server (ms)
jitterVariability of offset over recent samples (ms)

chrony

chrony is a modern, fast-converging NTP implementation. It handles intermittent connectivity well and is the default on RHEL/Fedora systems.

  • Daemon: chronyd
  • Client: chronyc
  • Configuration: /etc/chrony.conf

Typical /etc/chrony.conf:

pool pool.ntp.org iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync

makestep 1.0 3 allows a step adjustment if the offset is over 1 second during the first 3 clock updates.

chronyc Commands

CommandDescription
chronyc trackingShow clock performance summary (offset, drift, etc.)
chronyc sourcesList NTP sources and their status
chronyc ntpdataShow detailed NTP data for each source
chronyc makestepForce an immediate step correction of the clock
$ chronyc tracking
Reference ID    : A9FEA97B (time.example.com)
Stratum         : 3
Ref time (UTC)  : Mon Oct 21 13:45:00 2019
System time     : 0.000123456 seconds fast of NTP time
RMS offset      : 0.000045678 seconds
Frequency       : -12.345 ppm slow
Residual freq   : -0.001 ppm
Skew            : 0.012 ppm
Root delay      : 0.012345678 seconds
Root dispersion : 0.001234567 seconds

Quick Reference

System vs hardware clock:
  System clock    kernel-maintained, lost on reboot
  Hardware clock  battery-backed RTC, persists without power

date:
  date                     current time
  date -u                  UTC time
  date -I                  ISO 8601 (YYYY-MM-DD)
  date -R                  RFC 2822 format
  date +%s                 Unix epoch
  date --date=@EPOCH       epoch to human-readable
  date -s "DATETIME"       set system clock

hwclock:
  hwclock                  read hardware clock
  hwclock --systohc        hardware clock <- system clock
  hwclock --hctosys        system clock <- hardware clock
  hwclock --set --date=STR set hardware clock
  hwclock --verbose        detailed output

timedatectl:
  timedatectl                         show time/timezone/NTP status
  timedatectl set-time "DATETIME"     set time (NTP must be off)
  timedatectl list-timezones          list all timezones
  timedatectl set-timezone ZONE       set timezone
  timedatectl set-ntp true/false      enable/disable NTP
  timedatectl show-timesync --all     timesyncd details

NTP terms:
  Offset      difference between local and NTP time
  Step        large immediate correction
  Slew        gradual speed adjustment
  Drift       systematic clock rate error
  Jitter      variability in offset measurements
  Insane Time offset too large to correct (>1000s default)

ntpq:
  ntpq -p     show peer list (remote/refid/st/when/poll/reach/delay/offset/jitter)
  * prefix    selected server, + acceptable, - discarded

chronyc:
  chronyc tracking    clock performance summary
  chronyc sources     NTP source list
  chronyc ntpdata     detailed source data
  chronyc makestep    force immediate step correction

Config files:
  /etc/ntp.conf          ntpd configuration
  /etc/chrony.conf       chrony configuration
  /etc/systemd/timesyncd.conf   timesyncd configuration

Exam Questions

  1. What is the difference between the system clock and the hardware clock? โ†’ The system clock is maintained by the kernel in memory (lost on power-off); the hardware clock is a battery-backed RTC that persists without power.
  2. What command sets the hardware clock from the current system clock? โ†’ hwclock --systohc
  3. What command sets the system clock from the hardware clock? โ†’ hwclock --hctosys
  4. What does date +%s output? โ†’ The current Unix epoch (seconds since 1970-01-01 00:00:00 UTC).
  5. How do you set the system clock to a specific date and time with date? โ†’ date -s "YYYY-MM-DD HH:MM:SS"
  6. What does date --date=@1571661921 do? โ†’ Converts the Unix epoch 1571661921 to a human-readable date.
  7. What does timedatectl set-ntp true do? โ†’ Enables NTP synchronization via systemd-timesyncd.
  8. What command lists all available time zones on a systemd system? โ†’ timedatectl list-timezones
  9. What is a stratum 1 NTP server? โ†’ A server directly connected to a stratum 0 reference clock (atomic clock, GPS).
  10. What does the * prefix mean in ntpq -p output? โ†’ That server is the currently selected synchronization source.
  11. What does the reach column in ntpq -p show? โ†’ An octal bitmask of the last 8 polling attempts; 377 means all 8 succeeded.
  12. What NTP option in ntp.conf speeds up initial synchronization? โ†’ iburst โ€” sends a burst of packets at startup.
  13. What file stores ntpd’s clock drift information? โ†’ /var/lib/ntp/ntp.drift (as specified by driftfile in ntp.conf).
  14. What is chronyc tracking? โ†’ Shows clock performance: current offset, drift, stratum, and reference source.
  15. What does makestep 1.0 3 in chrony.conf do? โ†’ Allows a step correction if the offset exceeds 1 second, but only during the first 3 clock updates.
  16. What is the difference between step and slew in NTP? โ†’ Step is an immediate large correction; slew gradually adjusts clock speed to reduce the offset over time.
  17. What is pool.ntp.org? โ†’ A DNS-based pool of public NTP servers that distributes load across many hosts.
  18. What is systemd-timesyncd? โ†’ A lightweight SNTP client bundled with systemd, suitable for synchronizing time but not for serving time to other hosts.

Exercises

Exercise 1 โ€” Reading the Hardware Clock

What command reads the hardware clock and shows detailed output?

Answer
hwclock --verbose

Exercise 2 โ€” Converting an Epoch

The epoch value 1571661921 is shown in a log. How do you convert it to a readable date?

Answer
date --date=@1571661921

Exercise 3 โ€” Disabling NTP Before Setting Time

You want to set the system time manually to 2019-10-21 15:00:00. What two commands do you run?

Answer
timedatectl set-ntp false
timedatectl set-time "2019-10-21 15:00:00"

NTP must be disabled before setting the time manually with timedatectl.


Exercise 4 โ€” Reading ntpq Output

In ntpq -p output, a server shows reach of 377. What does that mean?

Answer

All 8 of the last polling attempts succeeded. 377 in octal equals 11111111 in binary, meaning every bit is set.


Exercise 5 โ€” Force chrony Step

The system clock is significantly off and chrony is running. How do you force an immediate step correction?

Answer
chronyc makestep

This forces an immediate large correction instead of waiting for the gradual slew process.


LPIC-1 Study Notes | Topic 108: Essential System Services