Skip to the text
KDOS
Menu
kdos.dev KDOS from Scratch KDOS 0.2 · 4dd4a10 · 2026-11-30 Contents Index

392. Time and NTP

KDOS keeps its clock with chrony, which starts at boot and needs no setting, and keeps the time zone in two files that always name the same zone. This page shows how to check that the clock is synchronised, how to set the time zone, how to use other time servers, and what to look at when the clock is wrong. Why the zone is written twice, and what else the zone sets, is in the KDOS book’s kdos-settingsd section.

Installation

What Port Started by
chronyd and chronyc chrony /etc/init.d/35_chrony.sh, at every boot
The zone database, /usr/share/zoneinfo tzdata read by the C library, nothing to start
org.freedesktop.timedate1, which sets the zone, the clock and network time kdos-settingsd /etc/init.d/43_settingsd.sh
The Date & Time page of System Settings, and the clock in the panel plasma-workspace System Settings

The two service scripts come from the tree’s fs/ overlay, not from the ports, and the image ships no marker for either in /etc/service.disabled/, so both start on the live medium and on an installed system. 35_chrony.sh runs after 30_network. The installer asks for the zone on its Time page and writes it; see 3. Time.

Configuration

/etc/chrony/chrony.conf is written by the chrony port, in ports/core/network/chrony/build.sh:

cat > "$PKG/etc/chrony/chrony.conf" <<'EOF'
pool pool.ntp.org iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
EOF

ports/core/network/chrony/build.sh, lines 29–34

pool names the servers, and iburst sends a quick burst of requests at the start so the first measurement arrives within seconds. driftfile is where chronyd keeps the rate error of this machine’s clock between boots. makestep 1.0 3 lets it step the clock instead of slewing it when it is more than one second out, during its first three updates only. rtcsync leaves the hardware clock to the kernel, which copies the system time to it every eleven minutes once the clock is synchronised (the kernel’s RTC_SYSTOHC option, on by default and not turned off in the kernel port’s ports/core/boot/linux/kdos.config); no init script runs hwclock. No allow line is present, so chronyd serves time to no other machine. Every directive is in chrony.conf(5).

The file belongs to the package: an upgrade of chrony installs it again over an edited copy, and kpkg check chrony lists the edit as chrony: config ./etc/chrony/chrony.conf (see Checking an installed root).

/etc/init.d/35_chrony.sh, from fs/etc/init.d/35_chrony.sh:

. /etc/init.d/service_helper

NAME="chronyd"
DAEMON="/usr/sbin/chronyd"

case "$1" in
    start)
        if [ ! -x "$DAEMON" ]; then
            echo "[SKIP] $NAME: $DAEMON not found"
            exit 0
        fi
        echo "[KDOS] Starting $NAME..."
        # 0750, set on every start: chronyd refuses its command socket in a
        # run directory others can open ("Wrong permissions on /run/chrony"),
        # and without the socket `chronyc makestep` and every other command
        # that changes the clock answers "501 Not authorised", even for root.
        install -d -m 0750 /run/chrony
        mkdir -p /var/lib/chrony
        # After 30_network: chronyd started before an interface exists just
        # logs unreachable pools until the first poll interval expires.
        #
        # No hwclock call anywhere in KDOS. The kernel does both directions
        # itself — CONFIG_RTC_HCTOSYS sets the clock at boot, CONFIG_RTC_SYSTOHC
        # writes it back every 11 minutes — and chrony.conf's `rtcsync` tells
        # chronyd to leave the RTC to the kernel rather than fight it.
        #
        # -d = foreground (chronyd's own flag; it is not a debug switch). It
        # also sends chronyd's messages to stderr instead of syslog, and
        # ksvc forwards that stderr to syslog under the service's name.
        supervise "$NAME" "$DAEMON" -d
        ;;
    stop)
        stop_service "$NAME"
        ;;
    status)
        check_status "$NAME"
        ;;
    *)
        echo "Usage: $0 {start|stop|status}"
        exit 1
        ;;
esac

fs/etc/init.d/35_chrony.sh

/etc/localtime is a symbolic link into /usr/share/zoneinfo. No package owns it. When nothing is there at boot, as on every boot of the live medium, rcS links UTC, from fs/etc/init.d/rcS:

# /etc/localtime belongs to no package, so a tzdata upgrade never rewrites a
# chosen zone, even one the new tzdata no longer lists. UTC is linked here only
# when nothing is there — every boot of the live medium, whose /etc starts as
# the image's — and a link that exists, dangling or not, is the machine's own
# choice and is left alone.
[ -L /etc/localtime ] || [ -e /etc/localtime ] || \
    ln -s /usr/share/zoneinfo/UTC /etc/localtime 2>/dev/null

fs/etc/init.d/rcS, lines 168–174

/etc/profile.d/20-timezone.sh sets TZ for every login shell. It is not in the tree: the installer writes it, and kdos-settingsd writes it on every zone change, so the live medium has none until the first one. The text, from src/daemons/kdos-settingsd/store.c:

	if (kb_write_file_atomic(prof,
		"# Written by kdos-settingsd (org.freedesktop.timedate1).\n"
		"# musl reads TZ before /etc/localtime; the colon form names\n"
		"# the link, so both say the same zone, and a running program\n"
		"# follows the link when it is replaced. A zone name here\n"
		"# would hold every program on that zone.\n"
		"export TZ=':/etc/localtime'\n") != 0)

src/daemons/kdos-settingsd/store.c, lines 994–1000

/etc/modprobe.d/kdos-regdom.conf is the wireless regulatory country, written from the zone by the same call; see /etc/modprobe.d/kdos-regdom.conf.

Usage

Checking that the clock is synchronised

  1. Ask chronyd how far off the clock is and from which server it takes the time. Any account can run it:

    chronyc tracking

    A Leap status of Normal means the clock is synchronised, and Not synchronised that chronyd has no usable source yet. System time is how far the clock is from the time chronyd has measured.

  2. List the servers it is using and how each is doing:

    chronyc sources -v

    The source marked * is the one the clock follows. -v prints a legend for the columns.

  3. Or open System Settings → Date & Time, which shows the zone, the clock and whether it is set automatically.

Setting the time zone

polkit lets the person at the machine do it; anyone else is asked for an administrator’s password.

  1. Find the zone’s name, Area/City. The list of current zones is the third column of zone1970.tab:

    grep -v '^#' /usr/share/zoneinfo/zone1970.tab | cut -f3 | sort | less
  2. Set it on System Settings → Date & Time → Time Zone, or from a prompt through timedate1:

    dbus-send --system --print-reply --dest=org.freedesktop.timedate1 \
        /org/freedesktop/timedate1 org.freedesktop.timedate1.SetTimezone \
        string:Europe/Berlin boolean:true

    /etc/localtime, TZ and the Wi-Fi country change together.

  3. Check with date. Programs already running follow the link too: KDOS’s musl re-reads it on the next tzset(), which Qt calls before every local time, so the panel clock moves at its next update. A C program that never calls tzset() keeps the zone it started with until it restarts, and a shell whose TZ names a zone, such as TZ=Asia/Tokyo, keeps that zone.

On the live medium, the zone lasts until power-off: /etc starts again as the image’s at every boot, and rcS links UTC. A persistence store keeps it (kdos persist).

Correcting a clock that is far off

chronyd corrects a small offset by running the clock slightly fast or slow, which can take a long time for a large one. To step it at once:

sudo chronyc makestep

It answers 200 OK. makestep needs root, because chronyc sends it over chronyd’s own socket, /run/chrony/chronyd.sock, which only root can reach; run by any other account it goes over 127.0.0.1 instead and is answered 501 Not authorised. The monitoring commands above go over 127.0.0.1 and need no privilege. chronyd opens the socket only in a run directory no other account can enter, which is why 35_chrony.sh sets /run/chrony to mode 0750 at every start.

Using other time servers

  1. Edit the configuration:

    sudoedit /etc/chrony/chrony.conf

    Replace the pool line with your own servers, one server line each:

    server ntp1.example.net iburst
    server ntp2.example.net iburst

    chronyd is built with NTS, authenticated NTP, through gnutls; chronyd -v lists +NTS. A server that offers it takes the nts option: server <host> iburst nts.

  2. Restart the daemon:

    sudo service restart chrony
  3. Check with chronyc sources -v.

Keep a copy of the edited file, because an upgrade of the chrony package puts the shipped one back (Configuration).

Tips

Troubleshooting

chronyc tracking prints 506 Cannot talk to daemon. chronyd is not running.

service status chrony
cat /run/kdos-init.chrony.log
sudo cat /run/kdos-svc.chronyd.log

The first log is the boot script’s output, the second chronyd’s own messages, readable by root only, which also go to /var/log/messages tagged chronyd; see Supervision and logging. Start it with sudo service start chrony.

sudo chronyc makestep prints 501 Not authorised. chronyd disabled its command socket. Its log says why:

sudo grep 'command socket\|Wrong permissions' /run/kdos-svc.chronyd.log

Wrong permissions on /run/chrony and Disabled command socket /run/chrony/chronyd.sock mean the directory is open to other accounts. Restart the service, which sets it back to 0750: sudo service restart chrony.

Leap status reads Not synchronised, and every source in chronyc sources shows ?. chronyd reaches no server. Check that the machine is online, and that the names in chrony.conf resolve: getent hosts pool.ntp.org. The firewall lets every outgoing packet through, and the answers back with it.

date shows UTC on an installed machine. rcS links UTC at boot when nothing is at /etc/localtime, and a link to a zone file that is not there reads as UTC too. ls -l /etc/localtime shows which; set the zone again as in Setting the time zone.

The Date & Time page cannot save. kdos-settingsd is not running: service status settingsd, and its log, sudo cat /run/kdos-svc.kdos-settingsd.log. A refusal names the zone it could not find under /usr/share/zoneinfo.

date and the desktop’s clock disagree. One of them was started before a zone change. Log out and in again.

Known gaps

Known gaps lists nothing for this topic.

See also