What is NTP ?
On any computer system, having a precise time set is crucial for running it. This is specially so for the Pogoplug E02 who doesn’t have a dedicated hardware RTC (real-time clock)1 to keep track of the current time. This means that after a reboot, the time is reset until it’s set manually. But because there is no hardware to maintain its correctness, we must use a time synchronization service to keep it in check. A protocol being used for that is called NTP (Network Time Protocol)2, who uses external services to set proper time in intervals.
For Linux systems there are various implementations of software to use the NTP protocol, one of them is actually part of the systemd3 suite that is packaged with an Arch Linux installation. It’s called
It’s configured in
/etc/systemd/timesyncd.conf and you can run it with the
systemctl command as following.
$ systemctl start systemd-timesyncd
But as we’re using the Arch Linux installation on an ARM device which uses an USB flash storage to keep the system, it’s beneficial to keep as less as possible write cycles to the system log as possible, so the storage doesn’t degrade that fast. The problem with the
systemd-timesyncd daemon is that it writes too much log data often with no way to stop.
We can see that with using the system log viewer command
journalctl and filtering the output with
-b switch displays whole log since boot.
$ sudo journalctl -b | grep timesyncd Aug 28 04:24:43 pogo systemd-timesyncd: Using NTP server 126.96.36.199:123 (0.arch.pool.ntp.org). Aug 28 04:26:03 pogo systemd-timesyncd: interval/delta/delay/jitter/drift 2048s/+0.001s/0.066s/0.002s/+27ppm Aug 28 05:00:11 pogo systemd-timesyncd: interval/delta/delay/jitter/drift 2048s/-0.002s/0.061s/0.003s/+26ppm Aug 28 05:34:19 pogo systemd-timesyncd: interval/delta/delay/jitter/drift 2048s/+0.002s/0.066s/0.002s/+27ppm Aug 28 06:08:27 pogo systemd-timesyncd: interval/delta/delay/jitter/drift 2048s/-0.002s/0.063s/0.003s/+26ppm
It’s obvious that using
systemd-timesyncd flash storage will have to write heavily throughout the day and that doesn’t sound good if we intend to keep the same USB key for a year or more. But there’s an alternative service for NTP synchronization.
Ntpd5 is an older NTP daemon, who does the same job. Installing it on an Arch Linux installation is a breeze using the built in
pacman6 package manager as we worked with it before in the initial installation post.
At first we stop and disable the
systemd-timesyncd daemon to keep it running at boot.
$ sudo systemctl stop systemd-timesyncd $ sudo systemctl disable systemd-timesyncd
Then we install the ntp7 package with
pacman, after updating the package source database first using the
$ sudo pacman -Sy $ sudo pacman -S ntp
The configuration for it is saved in
/etc/ntp.conf, with an option to change the desired NTP time servers and restricting where the queries may originate.
1 # Please consider joining the pool: 2 # 3 # http://www.pool.ntp.org/join.html 4 # 5 # For additional information see: 6 # - https://wiki.archlinux.org/index.php/Network_Time_Protocol_daemon 7 # - http://support.ntp.org/bin/view/Support/GettingStarted 8 # - the ntp.conf man page 9 10 # Associate to Arch's NTP pool 11 server 0.arch.pool.ntp.org 12 server 1.arch.pool.ntp.org 13 server 2.arch.pool.ntp.org 14 server 3.arch.pool.ntp.org 15 16 # By default, the server allows: 17 # - all queries from the local host 18 # - only time queries from remote hosts, protected by rate limiting and kod 19 restrict default kod limited nomodify nopeer noquery notrap 20 restrict 127.0.0.1 21 restrict ::1 22 23 # Location of drift file 24 driftfile /var/lib/ntp/ntp.drift
Default configuration is pretty good, so we can keep it as default. Now we just have to start the ntpd daemon.
$ sudo systemctl start ntpd
When checking the log file, we see that ntpd doesn’t log the synchronization queries at all, only starting and stopping the service.
$ sudo journalctl -b | grep ntpd Aug 28 17:07:39 pogo ntpd: ntpd email@example.com Fri Feb 6 18:06:44 UTC 2015 (1): Starting Aug 28 17:07:39 pogo ntpd: Command line: /usr/bin/ntpd -g -u ntp:ntp Aug 28 17:07:39 pogo ntpd: proto: precision = 2.385 usec (-19) Aug 28 17:07:39 pogo ntpd: Listen and drop on 0 v6wildcard [::]:123 Aug 28 17:07:39 pogo ntpd: Listen and drop on 1 v4wildcard 0.0.0.0:123 Aug 28 17:07:39 pogo ntpd: Listen normally on 2 lo 127.0.0.1:123 Aug 28 17:07:39 pogo ntpd: Listen normally on 3 eth0 192.168.1.2:123 Aug 28 17:07:39 pogo ntpd: Listen normally on 4 lo [::1]:123 Aug 28 17:07:39 pogo ntpd: Listen normally on 5 eth0 [fe80::225:31ff:fe04:9b90%2]:123 Aug 28 17:07:39 pogo ntpd: Listening on routing socket on fd #22 for interface updates
At the end, we set it to be run at boot and to update the time at network connection.
$ sudo systemctl enable ntpd $ echo "ExecUpPost='/usr/bin/ntpdate -u pool.ntp.org'">>/etc/netctl/eth0
As demonstrated above, running a Linux server with various services on a smaller ARM device with limited resources and capabilities requires a specialized mindset towards choosing those services, so we have find some alternatives that are better in the long run.
- http://en.wikipedia.org/wiki/Real-time_clock [return]
- http://en.wikipedia.org/wiki/Network_Time_Protocol [return]
- http://en.wikipedia.org/wiki/Systemd [return]
- https://wiki.archlinux.org/index.php/Systemd-timesyncd [return]
- http://en.wikipedia.org/wiki/Ntpd [return]
- https://wiki.archlinux.org/index.php/pacman [return]
- https://wiki.archlinux.org/index.php/Network_Time_Protocol_daemon [return]