If you want your system to behave like an usual personal computer,
loading time from the hardware clock at boot and keeping it updated
periodically with Internet time, I've also written a few steps to set up
the proper systemd services.
The cleanest solution would be recompiling the kernel with static RTC support. A good article explaining this can be found here at lemoneerlabs.com.
Another possibility is reading the clock and setting time from user space, and that's what I did, inspired by laziness :D
Well, laziness apart, I picked it because I didn't want to interfere
with kernel updates and have to recompile it manually in the future.
Here we go:
1. Create and enable rtc-init systemd service:
write in /etc/systemd/system/ a rtc-init.service file containing the following lines
Description=RTC Clock Setup and Time Sync
Then add in /usr/lib/systemd/scripts/ an rtc-setup shell script like this
echo ds1307 0x68 >/sys/bus/i2c/devices/i2c-1/new_device
echo "RTC DS1307 Installed"
echo "System Time synced with RTC Time"
and give it right permissions with
chmod 755 rtc-setup. Run
systemctl enable rtc-init to enable the service at startup.
2. Move to /usr/lib/systemd/system/ and make a backup copy of systemd-timesyncd with
cp systemd-timesyncd systemd-timesyncd.original,
then edit systemd-timesyncd as shown below
After=systemd-remount-fs.service systemd-tmpfiles-setup.service systemd-sysusers.service rtc-init.service
(file name may vary based on Ethernet interface name) commenting out ExecUpPost
Description='A basic dhcp ethernet connection'
This disables automatic time sync with ntpd (at network startup during boot), since it's already performed by systemd-timesyncd service.
4. Eventually run
$ timedatectl set-ntp true to enable the edited version of systemd-timesyncd service
Reboot and enjoy, your Pi should now load the rtc time at startup (in
a few seconds). Then, if you are connected to the internet the systemd-timesyncd service fetches current time with Simple NTP protocol and syncs it with system time and hardware time (your RTC).
I measured the clock drift disabling systemd-timesyncd service
for a couple of days. It turned out that the clock has an accuracy of
20 ppm, it lose a couple of seconds each day. It was more than
acceptable for me, since my Raspberry is always online and can sync time