md
Rasbian System Time
Draft: November 14, 2019
<-Home Automation Servers on Raspbian Buster Lite --
<-Installation and Configuration of Raspbian Buster Lite

When first turned on, a computer system has to get the correct time from an independent source. On desktop and portable computers, there are usually two sources: a real-time clock (RTC) and any one of many Network Time Protocol (NTP) servers or Simple Network Time Protocol (SNTP) servers found on the Internet. Like many other single board computers, the family of Raspberry Pi board does not have an RTC and may not be connected to a network at all or may not have access to the Internet. The Raspberry Pi which at that heart of our home automation system does have an after-market RTC and does have access to the Internet, yet problems related to time keeping have occurred.

The battery of an the RTC has a limited life span. Power outages due to inclement weather are inevitable. Such are the vicissitudes of the computer hobbyist's life. It can get as bad as in a country western song: my clock is dead, and my Internet won't talk to me. Let's be serious; there are worse catastrophes. Nevertheless, I was taken aback when Domoticz would shut down immediately upon starting after a "cold start" (the initial boot after power is turned on) because of a dead RTC battery. This incident, and the need to install an RTC on a new Raspbian Buster Lite installation are the root causes of my newly found interest in Linux time keeping. Thought a definitive solution to avoid this problem has yet to materialize, but I decided to document what I have found out so far.

Table of Contents

  1. Linux Date
  2. Fake Clock
  3. Systemd Time Sync

Linux Date toc

The command line utility date is used to read or set the system date and time. To show the current local time (to the best knowledge of the operating system) in a format corresponding to the current locale, simply enter the command without any option.

woopi@goldserver:~$ date Thu 14 Nov 19:13:29 AST 2019

If option -u (or -utc) is added, the date and time are displayed in universal time coordinates. It is also possible to specify the TZ (time zone) environment variable to get the local time in the specified zone.

woopi@goldserver:~$ date -u; TZ='Europe/Paris' date; date Thu 14 Nov 23:18:30 UTC 2019 Fri 15 Nov 00:18:30 CET 2019 Thu 14 Nov 19:18:30 AST 2019

It is possible to set the format used to display the time

woopi@goldserver:~$ date "+%Y-%m-%d %H:%M:%S" 2018-11-14 19:19:44

That particular format, corresponds to what is needed to set the time. Formatting could be more complex.

woopi@goldserver:~$ TZ="America/St_Johns" date "+%nPLACE: St. John's, (Newfoundland and Labrador)%n DAY: %A%n DATE: %Y/%m/%d%n TIME: %H:%M:%S%n ZONE: %Z (%:z)" PLACE: St. John's, (Newfoundland and Labrador) DAY: Thursday DATE: 2018/11/14 TIME: 19:51:12 ZONE: NST (-03:30)

See the man page for details about the date and time format strings. They always begin with the "+" character and use "%" as an escape character to start a sequence identifying a time or date element to display.

To set the time, use the -s option.

woopi@goldserver:~$ sudo date -s "2018-11-28 15:32:27" Wed 28 Nov 15:32:27 AST 2018

If it is more convenient to set the time using universal coordinated time, then use the -u option.

woopi@goldserver:~$ sudo date -u -s "2018-11-28 19:32:27" Wed 28 Nov 15:32:27 AST 2018

Here is some additional information not really necessary for what follows. Time zone information is kept in a directory called /usr/share/zoneinfo/. It contains directories for each region of the globe. For instance is content for the time zones covering the Americas. Instead of using time zone names, important cities in each time zone are identified.

woopi@goldserver:~$ ls /usr/share/zoneinfo/America/ Adak Coral_Harbour Havana Miquelon Rosario Anchorage Cordoba Hermosillo Moncton Santa_Isabel Anguilla Costa_Rica Indiana Monterrey Santarem Antigua Creston Indianapolis Montevideo Santiago Araguaina Cuiaba Inuvik Montreal Santo_Domingo Argentina Curacao Iqaluit Montserrat Sao_Paulo Aruba Danmarkshavn Jamaica Nassau Scoresbysund Asuncion Dawson Jujuy New_York Shiprock Atikokan Dawson_Creek Juneau Nipigon Sitka Atka Denver Kentucky Nome St_Barthelemy Bahia Detroit Knox_IN Noronha St_Johns Bahia_Banderas Dominica Kralendijk North_Dakota St_Kitts Barbados Edmonton La_Paz Ojinaga St_Lucia Belem Eirunepe Lima Panama St_Thomas Belize El_Salvador Los_Angeles Pangnirtung St_Vincent Blanc-Sablon Ensenada Louisville Paramaribo Swift_Current Boa_Vista Fortaleza Lower_Princes Phoenix Tegucigalpa Bogota Fort_Nelson Maceio Port-au-Prince Thule Boise Fort_Wayne Managua Porto_Acre Thunder_Bay Buenos_Aires Glace_Bay Manaus Port_of_Spain Tijuana Cambridge_Bay Godthab Marigot Porto_Velho Toronto Campo_Grande Goose_Bay Martinique Puerto_Rico Tortola Cancun Grand_Turk Matamoros Punta_Arenas Vancouver Caracas Grenada Mazatlan Rainy_River Virgin Catamarca Guadeloupe Mendoza Rankin_Inlet Whitehorse Cayenne Guatemala Menominee Recife Winnipeg Cayman Guayaquil Merida Regina Yakutat Chicago Guyana Metlakatla Resolute Yellowknife Chihuahua Halifax Mexico_City Rio_Branco

The current system timezone is a symbolic link to a city found in the time zone information directories.

woopi@goldserver:~$ ls -l /etc/localtime lrwxrwxrwx 1 root root 35 Nov 7 16:39 /etc/localtime -> /usr/share/zoneinfo/America/Halifax

While the date utility is quite valuable, it does not know the actual time. It can only display or set the system time. So the question remains "how does the system determine the correct time?"

Fake Clock toc

There is no real-time clock (RTC) on the Raspberry Pi. Instead, two software services, fake-hwclock and systemd-timesyncd try to provide a clock. So this investigation will start by looking at the "fake clock". In my humble opinion, fake-hwclock has a clear man page which is helpful for a neophyte like me. I suggest reading it.

woopi@goldserver:~$ man fake-hwclock

FAKE-HWCLOCK(8) System Manager's Manual FAKE-HWCLOCK(8) NAME fake-hwclock - Control fake hardware clock SYNOPSIS fake-hwclock [ command ] [ force ] BACKGROUND Many embedded Linux systems do not have a functional hardware clock. Either they simply don't have a hardware clock at all or they have a hardware clock but it is not usable (e.g. because Linux doesn't know how to use it or because no battery is present). This can lead to time moving backwards to some default value (often 1970) when the system is rebooted. Since lots of software assumes that time only moves forward this is a bad thing. NTP can (and should where practical) be used to sync with an external timeserver but it is not available early in the boot process and may be unavailable for other reasons. The design expectation of fake-hwclock is that it will be run very late at shutdown and very early at boot. This will ensure that fsck has a vaguely sensible idea of system time at boot and won't complain that the last-modified time in the filesystem is not hugely in the past or future. Some users may not worry about this too use case, in which case it is possible to modify the init system configuration to move things earlier/later as appropriate. DESCRIPTION fake-hwclock sets and queries a fake "hardware clock" which stores the time in a file. This program may be run by the system administrator di‐ rectly but is typically run by init (to load the time on startup and save it on shutdown) and cron (to save the time hourly). If no command is given then fake-hwclock acts as if the save command was used. COMMANDS save Save the time to the file. As a sanity check, fake-hwclock will not move the saved clock backwards to a time/date earlier than its own release date. Use "force" to over-ride this check. load Load the time from the file. If force is specified fake-hwclock will move the clock either backwards or forwards. Otherwise it will only move it forwards. FILES /etc/fake-hwclock.data The file used to store the time /etc/init.d/fake-hwclock The init script used to run fake-hwclock on startup and shutdown /lib/systemd/system/fake-hwclock.service systemd service used to run fake-hwclock on startup and shutdown /etc/default/fake-hwclock Settings file for the init script. /etc/cron.hourly/fake-hwclock Cron job used to save the time hourly ENVIRONMENT VARIABLES FILE set the file used by fake-hwclock RETURN VALUES 1 is returned for invalid commands. 0 is returned in all other cases.

To summarize, fake-hwclock (a dash script found in /sbin on Debian systems) saves the current date and time in a file named /etc/fake-hwclock.data just as the system is shutting down. When the system is starting, fake-hwclock sets the system time using the saved time and date from /etc/fake-hwclock.data. Also once an hour, it updates the date and time saved in /etc/fake-hwclock.data. With this last measure there's some assurance that that the time is advanced even if the system did not shutdown properly, should a power outage occur for example.

Here is a simplified version of the code that saves the system time as UTC time in hwclock.data and later reads it from the file and uses it to set the system time. The command line options save and load determine which operation is performed.

FILE=/etc/fake-hwclock.data case $1 in save) date -u '+%Y-%m-%d %H:%M:%S' > $FILE ;; load) SAVED="$(cat $FILE)" date -u -s "$SAVED" ;; esac

A systemd unit file instructs fake-hwclock to load the date at startup (ExecStart) and to save it at shutdown (ExecStop).

woopi@goldserver:~$ cat /lib/systemd/system/fake-hwclock.service [Unit] Description=Restore / save the current clock Documentation=man:fake-hwclock(8) DefaultDependencies=no Before=sysinit.target systemd-fsck-root.service Conflicts=shutdown.target [Service] EnvironmentFile=-/etc/default/fake-hwclock ExecStart=/sbin/fake-hwclock load $FORCE ExecStop=/sbin/fake-hwclock save Type=oneshot RemainAfterExit=yes [Install] WantedBy=sysinit.target

As can be seen the unit file is setting using an environment variable named FORCE as an option when loading the system time at boot from the /etc/fake-hwclock.data file. The default configuration file that will be used to define the value of FORCE does not define that variable.

woopi@goldserver:~$ cat /etc/default/fake-hwclock # Uncomment to set clock even if saved value appears to be in the past #FORCE=force

By default then, the load command issued by fake-hwclock.service at boot time will be fake-hwclock load. That means that a sanity check will be performed by fake-hwclock and it will not set the system time to any date prior to midnight 2016-04-15 even if /etc/fake-hwclock.data contained an older date.

Let's experiment with changes to the date and time to see how these impact the system time on reboot when no RTC is connected to the Raspberry Pi and when the Internet cannot be accessed. We begin by moving the time ahead from Nov. 13 to Nov. 16 at noon. After waiting about 18 minutes, the time in hwclock.data was updated to 16:17:41 UTC (12:17:41 local time).

woopi@goldserver:~$ date Wed 13 Nov 17:02:56 AST 2019 woopi@goldserver:~$ sudo date -s '2019-11-16 12:00:00' Sat 16 Nov 12:00:00 AST 2019 ... woopi@goldserver:~$ ls -l /etc/fake-hwclock.data -rw-r--r-- 1 root root 20 Nov 16 12:17 /etc/fake-hwclock.data woopi@goldserver:~$ cat /etc/fake-hwclock.data 2019-11-16 16:17:41

After waiting a couple of minutes, the system was rebooted and then time was checked again.

woopi@goldserver:~$ sudo reboot [ 6509.761790] reboot: Restarting system ... Last login: Wed Nov 13 15:35:54 AST 2019 on ttyS0 Linux goldserver 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. woopi@goldserver:~$ date Sat 16 Nov 12:20:27 AST 2019 woopi@goldserver:~$ ls -l /etc/fake-hwclock.data -rw-r--r-- 1 root root 20 Nov 16 12:19 /etc/fake-hwclock.data woopi@goldserver:~$ cat /etc/fake-hwclock.data 2019-11-16 16:19:26

The time in hwclock.data was updated to 2019-11-16 16:19:26 (12:19:26 local time) during the shutdown process and then read back from the file early in the boot process. When the date command was issued the time had progressed to 12:20:27. This shows fake-hwclock performing its task of moving a record of the system time forward.

Let's move the time backwards, but not so far back as to run afoul of fake-hwclock sanity check.

woopi@goldserver:~$ date Sat 16 Nov 12:24:23 AST 2019 woopi@goldserver:~$ sudo date -s '2019-10-13 12:00:00' Sun 13 Oct 12:00:00 ADT 2019 ... woopi@goldserver:~$ date Sun 13 Oct 12:01:55 ADT 2019 woopi@goldserver:~$ ls -l /etc/fake-hwclock.data -rw-r--r-- 1 root root 20 Nov 16 2019 /etc/fake-hwclock.data ... woopi@goldserver:~$ date Sun 13 Oct 12:28:03 ADT 2019 woopi@goldserver:~$ ls -l /etc/fake-hwclock.data -rw-r--r-- 1 root root 20 Oct 13 12:17 /etc/fake-hwclock.data woopi@goldserver:~$ cat /etc/fake-hwclock.data 2019-10-13 15:17:01

After waiting a couple of minutes, the system was rebooted and then time was checked again.

woopi@goldserver:~$ sudo reboot [ 6509.761790] reboot: Restarting system ... Last login: Sat Nov 16 12:20:25 AST 2019 on ttyS0 Linux goldserver 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. woopi@goldserver:~$ date Wed 13 Nov 15:36:51 AST 2019 woopi@goldserver:~$ ls -l /etc/fake-hwclock.data -rw-r--r-- 1 root root 20 Oct 13 12:28 /etc/fake-hwclock.data woopi@goldserver:~$ cat /etc/fake-hwclock.data 2019-10-13 15:28:06

Now that is a surprising result. The time according to fake-hwclock and the system was moved back to about 12:28 on Oct. 13 before rebooting yet the time and date after booting was Nov 13 15:37. How can that be? Looking at the system logs reveals that systemd-timesyncd manipulated the date even though it could not access the Internet.

Feb 14 06:11:59 goldserver kernel: bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer Oct 13 12:28:06 goldserver systemd[1]: System time before build time, advancing clock. Oct 13 12:28:06 goldserver fake-hwclock[105]: Sun 13 Oct 15:28:06 UTC 2019 Oct 13 12:28:06 goldserver systemd[1]: Started File System Check Daemon to report status. ... Oct 13 12:28:06 goldserver systemd-fsck[127]: e2fsck 1.44.5 (15-Dec-2018) Oct 13 12:28:06 goldserver systemd-fsck[127]: Superblock last mount time (Sat Nov 16 12:19:26 2019, Oct 13 12:28:06 goldserver systemd-fsck[127]: now = Sun Oct 13 12:28:06 2019) is in the future. ... Oct 13 12:28:13 goldserver systemd[1]: Started Raise network interfaces. Oct 13 12:28:13 goldserver systemd-timesyncd[257]: System clock time unset or jumped backwards, restoring from recorded timestamp: Wed 2019-11-13 15:34:18 AST Nov 13 15:34:18 goldserver systemd[1]: Started Network Time Synchronization. ... Nov 13 15:34:18 goldserver cron[316]: (CRON) INFO (Running @reboot jobs) Nov 13 15:34:18 goldserver systemd[1]: Reached target System Time Synchronized. Nov 13 15:34:18 goldserver systemd[1]: apt-daily.timer: Not using persistent file timestamp Sat 2019-11-16 12:00:00 AST as it is in the future. ... Nov 13 15:34:47 goldserver systemd[1]: systemd-fsckd.service: Succeeded.
Test this set up in the following circumstances fake-hwclock enabled 1. no RTC, no network 2. RTC with dead battery, no network 3. RTC with dead battery, with network 4. RTC, no network 5 RTC, with network fake-hwclock not enabled 1. no RTC, no network 2. RTC with dead battery, no network 3. RTC with dead battery, with network 4. RTC, no network 5 RTC, with network ========= oopi@goldserver:~ $ sudo nano /boot/config.txt ... # Uncomment some or all of these to enable the optional hardware interfaces dtparam=i2c_arm=on dtoverlay=i2c-rtc,rtc-ds1307=0x68 #dtparam=i2s=on #dtparam=spi=on ... woopi@goldserver:~ $ sudo nano /etc/modules-load.d/i2c.conf #etc/modules-load.d/i2c.conf i2c-dev i2c-bcm2835 rtc-ds1307 reboot woopi@goldserver:~ $ dmesg | grep -i i2c [ 3.260255] i2c /dev entries driver woopi@goldserver:~ $ lsmod | grep i2c i2c_bcm2835 16384 0 i2c_dev 20480 0 Nov 13 13:23:37 goldserver systemd-modules-load[223]: Failed to find module 'i2c:rtc-ds1307' woopi@goldserver:~ $ journalctl --no-pager | grep -i systemd-modules-load Nov 13 14:24:45 goldserver systemd-modules-load[96]: Inserted module 'i2c_dev' Nov 13 14:24:45 goldserver systemd-modules-load[96]: Inserted module 'i2c_bcm2835' Nov 13 14:24:45 goldserver systemd-modules-load[96]: Inserted module 'rtc_ds1307' woopi@goldserver:~ $ lsmod | grep -i i2c i2c_bcm2835 16384 0 i2c_dev 20480 0 woopi@goldserver:~ $ lsmod | grep -i rtc rtc_ds1307 24576 0 hwmon 16384 2 rtc_ds1307,raspberrypi_hwmon woopi@goldserver:~ $ ls /lib/modules/4.19.75-v7+/kernel/drivers/rtc rtc-abx80x.ko rtc-ds1307.ko rtc-ds3232.ko rtc-isl1208.ko rtc-max6900.ko rtc-pcf8523.ko rtc-rs5c348.ko rtc-rx4581.ko rtc-x1205.ko rtc-bq32k.ko rtc-ds1374.ko rtc-em3027.ko rtc-m41t80.ko rtc-max6902.ko rtc-pcf8563.ko rtc-rs5c372.ko rtc-rx8025.ko rtc-ds1302.ko rtc-ds1390.ko rtc-fm3130.ko rtc-m41t93.ko rtc-pcf2123.ko rtc-pcf8583.ko rtc-rv3028.ko rtc-rx8581.ko rtc-ds1305.ko rtc-ds1672.ko rtc-isl12022.ko rtc-m41t94.ko rtc-pcf2127.ko rtc-r9701.ko rtc-rv3029c2.ko rtc-s35390a.ko -------------------- Debian gnome $$$$$$$$$$$$$$$ woopi@goldserver:~ $ journalctl --no-pager | grep -i time Nov 13 15:10:45 goldserver systemd[1]: System time before build time, advancing clock. Nov 13 15:10:58 goldserver systemd[1]: Starting Network Time Synchronization... Nov 13 15:10:58 goldserver systemd[1]: Started Network Time Synchronization. Nov 13 15:10:58 goldserver systemd[1]: Reached target System Time Synchronized. Nov 13 15:11:29 goldserver systemd-timesyncd[262]: Synchronized to time server for the first time [2607:5300:60:975a::123 (2.debian.pool.ntp.org). Nov 13 15:10:45 goldserver kernel: clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x46d987e47, max_idle_ns: 440795202767 ns Nov 13 15:10:45 goldserver systemd[1]: System time before build time, advancing clock. Nov 13 15:10:45 goldserver fake-hwclock[102]: Wed 13 Nov 19:10:45 UTC 2019 woopi@goldserver:~$ ping 8.8.8.8 connect: Network is unreachable woopi@goldserver:~ $ dmesg | grep -i time [ 0.000000] arch_timer: cp15 timer(s) running at 19.20MHz (phys). [ 0.000023] Switching to timer-based delay loop, resolution 52ns [ 0.000968] Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=192000) [ 0.219185] workingset: timestamp_bits=14 max_order=18 bucket_order=4 [ 0.823475] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer [ 1.839000] systemd[1]: System time before build time, advancing clock. woopi@goldserver:~$ journalctl --no-pager | grep -i time Nov 13 15:34:18 goldserver kernel: arch_timer: cp15 timer(s) running at 19.20MHz (phys). Nov 13 15:34:18 goldserver kernel: Switching to timer-based delay loop, resolution 52ns Nov 13 15:34:18 goldserver kernel: Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=192000) Nov 13 15:34:18 goldserver kernel: workingset: timestamp_bits=14 max_order=18 bucket_order=4 Nov 13 15:34:18 goldserver kernel: bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer Nov 13 15:34:18 goldserver systemd[1]: System time before build time, advancing clock. Nov 13 15:34:18 goldserver systemd-journald[113]: Runtime journal (/run/log/journal/f77133b8ac624a31a8141c75e812672e) is 6.0M, max 48.7M. Nov 13 15:34:18 goldserver systemd-journald[113]: Runtime journal (/run/log/journal/f77133b8ac624a31a8141c75e812672e) is 6.0M, max 48.7M. Nov 13 15:35:30 goldserver systemd[1]: Starting Network Time Synchronization... Nov 13 15:35:31 goldserver systemd[1]: Started Network Time Synchronization. Nov 13 15:35:31 goldserver systemd[1]: Reached target System Time Synchronized. Nov 13 15:35:31 goldserver systemd[1]: Reached target Timers. Nov 13 15:36:02 goldserver dhcpcd[350]: timed out Nov 13 15:36:02 goldserver dhcpcd[350]: timed out Nov 13 15:36:20 goldserver systemd[1]: Starting User Runtime Directory /run/user/1000... Nov 13 15:36:20 goldserver systemd[1]: Started User Runtime Directory /run/user/1000. Nov 13 15:36:20 goldserver systemd[456]: Reached target Timers.

More to come...

woopi@goldserver:~$ journalctl --no-pager | grep -i clock Nov 13 15:34:18 goldserver systemd[1]: System time before build time, advancing clock. -----rtc with dead battery, no net ---------- goldserver login: woopi Password: Last login: Wed Nov 13 15:35:35 AST 2019 on ttyS0 Linux goldserver 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. woopi@goldserver:~$ date Wed 13 Nov 15:35:20 AST 2019 woopi@goldserver:~$ sudo hwclock -r 1999-12-31 20:01:31.093155-04:00 woopi@goldserver:~$ ls 0.txt 1.txt 2.txt 3.txt 4.txt 5.txt woopi@goldserver:~$ cat *txt at /run/systemd/system got to 1 got to 2 got to 3 loaded /etc/default/hwclok running hwclock (/dev/rtc0) woopi@goldserver:~$ ls -l total 24 -rw-r--r-- 1 root root 23 Nov 13 15:37 0.txt -rw-r--r-- 1 root root 9 Nov 13 15:37 1.txt -rw-r--r-- 1 root root 9 Nov 13 15:37 2.txt -rw-r--r-- 1 root root 9 Nov 13 15:37 3.txt -rw-r--r-- 1 root root 27 Nov 13 15:37 4.txt -rw-r--r-- 1 root root 28 Nov 13 15:37 5.txt woopi@goldserver:~$ date Wed 13 Nov 15:38:24 AST 2019 woopi@goldserver:~$ sudo hwclock -r 1999-12-31 20:04:29.626298-04:00 woopi@goldserver:~$ ls -l total 24 -rw-r--r-- 1 root root 23 Nov 13 15:37 0.txt -rw-r--r-- 1 root root 9 Nov 13 15:37 1.txt -rw-r--r-- 1 root root 9 Nov 13 15:37 2.txt -rw-r--r-- 1 root root 9 Nov 13 15:37 3.txt -rw-r--r-- 1 root root 27 Nov 13 15:37 4.txt -rw-r--r-- 1 root root 28 Nov 13 15:37 5.txt woopi@goldserver:~$ date Wed 13 Nov 15:38:58 AST 2019 woopi@goldserver:~$ dmesg | grep -i time [ 0.000000] arch_timer: cp15 timer(s) running at 19.20MHz (phys). [ 0.000023] Switching to timer-based delay loop, resolution 52ns [ 0.000971] Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIP) [ 0.219276] workingset: timestamp_bits=14 max_order=18 bucket_order=4 [ 0.827354] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer [ 3.067587] systemd[1]: System time before build time, advancing clock. [ 5.256728] systemd-journald[106]: Received request to flush runtime journal from PID 1 [ 6.716001] rtc-ds1307 1-0068: SET TIME! dmesg | grep -i rtc [ 6.716001] rtc-ds1307 1-0068: SET TIME! [ 6.719418] rtc-ds1307 1-0068: registered as rtc0 woopi@goldserver:~$ journalctl --no-pager | grep -i rtc Nov 13 15:37:16 goldserver kernel: rtc-ds1307 1-0068: SET TIME! Nov 13 15:37:16 goldserver kernel: rtc-ds1307 1-0068: registered as rtc0 woopi@goldserver:~$ journalctl --no-pager | grep -i time Nov 13 15:37:14 goldserver kernel: arch_timer: cp15 timer(s) running at 19.20MHz (phys). Nov 13 15:37:14 goldserver kernel: Switching to timer-based delay loop, resolution 52ns Nov 13 15:37:14 goldserver kernel: Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=192000) Nov 13 15:37:14 goldserver kernel: workingset: timestamp_bits=14 max_order=18 bucket_order=4 Nov 13 15:37:14 goldserver kernel: bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer Nov 13 15:37:14 goldserver systemd[1]: System time before build time, advancing clock. Nov 13 15:37:14 goldserver systemd-journald[106]: Runtime journal (/run/log/journal/f77133b8ac624a31a8141c75e812672e) is 6.0M, max 48.7M, 42.6M free. Nov 13 15:37:14 goldserver systemd-fsck[124]: Superblock last mount time is in the future. Nov 13 15:37:14 goldserver systemd-fsck[124]: Superblock last write time is in the future. Nov 13 15:37:14 goldserver systemd-journald[106]: Runtime journal (/run/log/journal/f77133b8ac624a31a8141c75e812672e) is 6.0M, max 48.7M, 42.6M free. Nov 13 15:37:16 goldserver kernel: rtc-ds1307 1-0068: SET TIME! Dec 31 20:00:12 goldserver systemd[1]: Starting Network Time Synchronization... Dec 31 20:00:12 goldserver systemd-timesyncd[265]: System clock time unset or jumped backwards, restoring from recorded timestamp: Wed 2019-11-13 15:34:18 AST Nov 13 15:34:18 goldserver systemd[1]: Started Network Time Synchronization. Nov 13 15:34:18 goldserver systemd[1]: Reached target System Time Synchronized. Nov 13 15:34:18 goldserver systemd[1]: Reached target Timers. Nov 13 15:34:49 goldserver dhcpcd[324]: timed out Nov 13 15:34:49 goldserver dhcpcd[324]: timed out Nov 13 15:35:07 goldserver systemd[1]: Starting User Runtime Directory /run/user/1000... Nov 13 15:35:07 goldserver systemd[1]: Started User Runtime Directory /run/user/1000. Nov 13 15:35:08 goldserver systemd[458]: Reached target Timers. woopi@goldserver:~$ journalctl --no-pager | grep -i clock Nov 13 15:37:14 goldserver kernel: clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x46d987e47, max_idle_ns: 440795202767 ns Nov 13 15:37:14 goldserver kernel: sched_clock: 56 bits at 19MHz, resolution 52ns, wraps every 4398046511078ns Nov 13 15:37:14 goldserver kernel: clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns Nov 13 15:37:14 goldserver kernel: clocksource: Switched to clocksource arch_sys_counter Nov 13 15:37:14 goldserver systemd[1]: System time before build time, advancing clock. Nov 13 15:37:14 goldserver fake-hwclock[101]: Wed 13 Nov 19:37:14 UTC 2019 Nov 13 15:37:14 goldserver systemd-fsck[124]: (by less than a day, probably due to the hardware clock being incorrectly set) Nov 13 15:37:14 goldserver systemd-fsck[124]: (by less than a day, probably due to the hardware clock being incorrectly set) Dec 31 20:00:12 goldserver systemd-timesyncd[265]: System clock time unset or jumped backwards, restoring from recorded timestamp: Wed 2019-11-13 15:34:18 AST ------------------- no rtc, no net ------------------------------------- Last login: Wed Nov 13 15:35:07 AST 2019 on ttyS0 Linux goldserver 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. woopi@goldserver:~$ date Wed 13 Nov 15:49:21 AST 2019 --- real date Wed 13 Nov 16:53 AST 2019 woopi@goldserver:~$ woopi@goldserver:~$ ls /dev/rt* ls: cannot access '/dev/rt*': No such file or directory woopi@goldserver:~$ dmesg | grep -i -E "time|clock|rtc|i2c" [ 0.000000] arch_timer: cp15 timer(s) running at 19.20MHz (phys). [ 0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x46d987e47, max_idle_ns: 440795202767 ns [ 0.000007] sched_clock: 56 bits at 19MHz, resolution 52ns, wraps every 4398046511078ns [ 0.000023] Switching to timer-based delay loop, resolution 52ns [ 0.000971] Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=192000) [ 0.021682] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns [ 0.111738] clocksource: Switched to clocksource arch_sys_counter [ 0.219155] workingset: timestamp_bits=14 max_order=18 bucket_order=4 [ 0.827262] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer [ 3.056582] systemd[1]: System time before build time, advancing clock. [ 5.232990] systemd-journald[112]: Received request to flush runtime journal from PID 1 [ 6.714487] rtc-ds1307: probe of 1-0068 failed with error -121 woopi@goldserver:~$ journalctl --no-pager | grep -i -E "time|clock|rtc|i2c" Nov 13 15:47:46 goldserver kernel: arch_timer: cp15 timer(s) running at 19.20MHz (phys). Nov 13 15:47:46 goldserver kernel: clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x46d987e47, max_idle_ns: 440795202767 ns Nov 13 15:47:46 goldserver kernel: sched_clock: 56 bits at 19MHz, resolution 52ns, wraps every 4398046511078ns Nov 13 15:47:46 goldserver kernel: Switching to timer-based delay loop, resolution 52ns Nov 13 15:47:46 goldserver kernel: Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=192000) Nov 13 15:47:46 goldserver kernel: clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns Nov 13 15:47:46 goldserver kernel: clocksource: Switched to clocksource arch_sys_counter Nov 13 15:47:46 goldserver kernel: workingset: timestamp_bits=14 max_order=18 bucket_order=4 Nov 13 15:47:46 goldserver kernel: bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer Nov 13 15:47:46 goldserver systemd[1]: System time before build time, advancing clock. Nov 13 15:47:46 goldserver systemd-journald[112]: Runtime journal (/run/log/journal/f77133b8ac624a31a8141c75e812672e) is 6.0M, max 48.7M, 42.6M free. Nov 13 15:47:46 goldserver fake-hwclock[101]: Wed 13 Nov 19:47:46 UTC 2019 Nov 13 15:47:46 goldserver systemd-journald[112]: Runtime journal (/run/log/journal/f77133b8ac624a31a8141c75e812672e) is 6.0M, max 48.7M, 42.6M free. Nov 13 15:47:48 goldserver kernel: rtc-ds1307: probe of 1-0068 failed with error -121 Nov 13 15:47:49 goldserver systemd[1]: Starting Network Time Synchronization... Nov 13 15:47:49 goldserver systemd[1]: Started Network Time Synchronization. Nov 13 15:47:50 goldserver systemd[1]: Reached target System Time Synchronized. Nov 13 15:47:50 goldserver systemd[1]: Reached target Timers. Nov 13 15:48:21 goldserver dhcpcd[298]: timed out Nov 13 15:48:21 goldserver dhcpcd[298]: timed out Nov 13 15:49:13 goldserver systemd[1]: Starting User Runtime Directory /run/user/1000... Nov 13 15:49:13 goldserver systemd[1]: Started User Runtime Directory /run/user/1000. Nov 13 15:49:13 goldserver systemd[447]: Reached target Timers. -----rtc with dead battery, no net ---------- goldserver login: woopi Password: Last login: Wed Nov 13 15:49:13 AST 2019 on ttyS0 Linux goldserver 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. woopi@goldserver:~$ date Wed 13 Nov 15:35:06 AST 2019 woopi@goldserver:~$ ls /dev/rt* /dev/rtc /dev/rtc0 woopi@goldserver:~$ dmesg | grep -i -E "time|clock|rtc|i2c" [ 0.000000] arch_timer: cp15 timer(s) running at 19.20MHz (phys). [ 0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x46d987e47, max_idle_ns: 440795202767 ns [ 0.000007] sched_clock: 56 bits at 19MHz, resolution 52ns, wraps every 4398046511078ns [ 0.000023] Switching to timer-based delay loop, resolution 52ns [ 0.000971] Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=192000) [ 0.021661] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns [ 0.111757] clocksource: Switched to clocksource arch_sys_counter [ 0.219076] workingset: timestamp_bits=14 max_order=18 bucket_order=4 [ 0.827274] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer [ 3.060965] systemd[1]: System time before build time, advancing clock. [ 5.259998] systemd-journald[103]: Received request to flush runtime journal from PID 1 [ 6.767709] rtc-ds1307 1-0068: SET TIME! [ 6.770050] rtc-ds1307 1-0068: registered as rtc0 woopi@goldserver:~$ journalctl --no-pager | grep -i -E "time|clock|rtc|i2c" Nov 13 15:58:35 goldserver kernel: arch_timer: cp15 timer(s) running at 19.20MHz (phys). Nov 13 15:58:35 goldserver kernel: clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x46d987e47, max_idle_ns: 440795202767 ns Nov 13 15:58:35 goldserver kernel: sched_clock: 56 bits at 19MHz, resolution 52ns, wraps every 4398046511078ns Nov 13 15:58:35 goldserver kernel: Switching to timer-based delay loop, resolution 52ns Nov 13 15:58:35 goldserver kernel: Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=192000) Nov 13 15:58:35 goldserver kernel: clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns Nov 13 15:58:35 goldserver kernel: clocksource: Switched to clocksource arch_sys_counter Nov 13 15:58:35 goldserver kernel: workingset: timestamp_bits=14 max_order=18 bucket_order=4 Nov 13 15:58:35 goldserver kernel: bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer Nov 13 15:58:35 goldserver systemd[1]: System time before build time, advancing clock. Nov 13 15:58:35 goldserver systemd-journald[103]: Runtime journal (/run/log/journal/f77133b8ac624a31a8141c75e812672e) is 6.0M, max 48.7M, 42.6M free. Nov 13 15:58:35 goldserver fake-hwclock[102]: Wed 13 Nov 19:58:35 UTC 2019 Nov 13 15:58:35 goldserver systemd-journald[103]: Runtime journal (/run/log/journal/f77133b8ac624a31a8141c75e812672e) is 6.0M, max 48.7M, 42.6M free. Nov 13 15:58:37 goldserver kernel: rtc-ds1307 1-0068: SET TIME! Nov 13 15:58:37 goldserver kernel: rtc-ds1307 1-0068: registered as rtc0 Dec 31 20:00:20 goldserver systemd[1]: Starting Network Time Synchronization... Dec 31 20:00:21 goldserver systemd-timesyncd[265]: System clock time unset or jumped backwards, restoring from recorded timestamp: Wed 2019-11-13 15:34:18 AST Nov 13 15:34:18 goldserver systemd[1]: Started Network Time Synchronization. Nov 13 15:34:18 goldserver systemd[1]: Reached target System Time Synchronized. Nov 13 15:34:18 goldserver systemd[1]: Reached target Timers. Nov 13 15:34:49 goldserver dhcpcd[307]: timed out Nov 13 15:34:49 goldserver dhcpcd[307]: timed out Nov 13 15:35:02 goldserver systemd[1]: Starting User Runtime Directory /run/user/1000... Nov 13 15:35:02 goldserver systemd[1]: Started User Runtime Directory /run/user/1000. Nov 13 15:35:02 goldserver systemd[457]: Reached target Timers. woopi@goldserver:~$ ls -l /var/lib/systemd/timesync total 0 -rw-r--r-- 1 systemd-timesync systemd-timesync 0 Nov 13 15:34 clock --looks like systemd-journald keeps its own time stamp independant of fake-hwclock -----rtc with good battery, no net ---------- Password: Last login: Wed Nov 13 15:35:02 AST 2019 on ttyS0 Linux goldserver 4.19.75-v7+ #1270 SMP Tue Sep 24 18:45:11 BST 2019 armv7l The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. woopi@goldserver:~$ date Wed 13 Nov 17:32:23 AST 2019 woopi@goldserver:~$ ls /dev/rt* /dev/rtc /dev/rtc0 oopi@goldserver:~$ dmesg | grep -i -E "time|clock|rtc|i2c" [ 0.000000] arch_timer: cp15 timer(s) running at 19.20MHz (phys). [ 0.000000] clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x46d987e47, max_idle_ns: 440795202767 ns [ 0.000007] sched_clock: 56 bits at 19MHz, resolution 52ns, wraps every 4398046511078ns [ 0.000023] Switching to timer-based delay loop, resolution 52ns [ 0.000971] Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=192000) [ 0.021678] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns [ 0.111775] clocksource: Switched to clocksource arch_sys_counter [ 0.219289] workingset: timestamp_bits=14 max_order=18 bucket_order=4 [ 0.827019] bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer [ 3.056618] systemd[1]: System time before build time, advancing clock. [ 5.264132] systemd-journald[108]: Received request to flush runtime journal from PID 1 [ 6.839044] rtc-ds1307 1-0068: registered as rtc0 woopi@goldserver:~$ journalctl --no-pager | grep -i -E "time|clock|rtc|i2c" Nov 13 15:49:02 goldserver kernel: arch_timer: cp15 timer(s) running at 19.20MHz (phys). Nov 13 15:49:02 goldserver kernel: clocksource: arch_sys_counter: mask: 0xffffffffffffff max_cycles: 0x46d987e47, max_idle_ns: 440795202767 ns Nov 13 15:49:02 goldserver kernel: sched_clock: 56 bits at 19MHz, resolution 52ns, wraps every 4398046511078ns Nov 13 15:49:02 goldserver kernel: Switching to timer-based delay loop, resolution 52ns Nov 13 15:49:02 goldserver kernel: Calibrating delay loop (skipped), value calculated using timer frequency.. 38.40 BogoMIPS (lpj=192000) Nov 13 15:49:02 goldserver kernel: clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns Nov 13 15:49:02 goldserver kernel: clocksource: Switched to clocksource arch_sys_counter Nov 13 15:49:02 goldserver kernel: workingset: timestamp_bits=14 max_order=18 bucket_order=4 Nov 13 15:49:02 goldserver kernel: bcm2835-wdt bcm2835-wdt: Broadcom BCM2835 watchdog timer Nov 13 15:49:02 goldserver systemd[1]: System time before build time, advancing clock. Nov 13 15:49:02 goldserver systemd-journald[108]: Runtime journal (/run/log/journal/f77133b8ac624a31a8141c75e812672e) is 6.0M, max 48.7M, 42.6M free. Nov 13 15:49:02 goldserver fake-hwclock[97]: Wed 13 Nov 19:49:02 UTC 2019 Nov 13 15:49:02 goldserver systemd-fsck[125]: Superblock last mount time is in the future. Nov 13 15:49:02 goldserver systemd-fsck[125]: (by less than a day, probably due to the hardware clock being incorrectly set) Nov 13 15:49:02 goldserver systemd-journald[108]: Runtime journal (/run/log/journal/f77133b8ac624a31a8141c75e812672e) is 6.0M, max 48.7M, 42.6M free. Nov 13 15:49:04 goldserver kernel: rtc-ds1307 1-0068: registered as rtc0 Nov 13 15:49:06 goldserver systemd[1]: Starting Network Time Synchronization... Nov 13 17:31:16 goldserver systemd[1]: Started Network Time Synchronization. Nov 13 17:31:16 goldserver systemd[1]: Reached target System Time Synchronized. Nov 13 17:31:16 goldserver systemd[1]: Reached target Timers. Nov 13 17:31:50 goldserver dhcpcd[315]: timed out Nov 13 17:31:50 goldserver dhcpcd[315]: timed out Nov 13 17:32:20 goldserver systemd[1]: Starting User Runtime Directory /run/user/1000... Nov 13 17:32:20 goldserver systemd[1]: Started User Runtime Directory /run/user/1000. Nov 13 17:32:20 goldserver systemd[456]: Reached target Timers. woopi@goldserver:~$ woopi@goldserver:~$ ls -l /var/lib/systemd/timesync total 0 -rw-r--r-- 1 systemd-timesync systemd-timesync 0 Nov 13 15:34 clock woopi@goldserver:~$ date; sudo hwclock -r Wed 13 Nov 17:37:21 AST 2019 2019-11-13 17:37:33.906765-04:00 woopi@goldserver:~$ sudo ls -l /run/systemd/timesync/ total 0 no synchronization, yet RTC gave good date ///////////////// woopi@goldserver:~$ /lib/systemd/systemd-time-wait-sync adjtime state 5 status 40 time Wed 2019-11-13 21:47:47.816793 UTC How can I delay the startup of systemd services until the datetime is set (no RTC on the Raspberry Pi) https://raspberrypi.stackexchange.com/questions/94635/how-can-i-delay-the-startup-of-systemd-services-until-the-datetime-is-set-no-rt maybe [Unit] Description=SDS011 Feinstaub Sensor After=time-sync.target Wants=time-sync.target SO if network down, Raspberry Read Only File System https://gist.github.com/Lahorde/d459695668ed299beec5af20dd34f0f4#description
<-Home Automation Servers on Raspbian Buster Lite --
<-Installation and Configuration of Raspbian Buster Lite