Raspberry Pi – NTP Won’t Work on Read-Only System

ntpntpd

I'm struggling to understand WHY ntp (the service) won't set the time correctly on my raspberry pi.

I have configured the filesystem as read only, to save my SD card, but it used to work, and I cannot seem to figure out why ntp won't work now.

In the logs I get many many lines of that message:

ntpd[415]: kernel reports TIME_ERROR: 0x41: Clock Unsynchronized
ntpd[415]: kernel reports TIME_ERROR: 0x41: Clock Unsynchronized
ntpd[415]: error resolving pool 0.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 1.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 2.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 3.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 3.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 2.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 1.debian.pool.ntp.org: Temporary failure in name resolution (-3)
ntpd[415]: error resolving pool 0.debian.pool.ntp.org: Temporary failure in name resolution (-3)

My /etc/resolv.conf looks like this:

# Generated by resolvconf
nameserver 8.8.8.8
nameserver 192.168.1.22

I have access to internet on that RPi, I can ping the pool addresses, I can ping google, I can apt update (after remounting in rw)…

I also can issue an ntpdate command manually and IT WORKS!

$ sudo ntpdate -u 0.fr.pool.ntp.org 1.fr.pool.ntp.org
24 Nov 23:04:34 ntpdate[578]: step time server 129.250.35.250 offset 2418.621037 sec

So yeah, I'm pulling hairs here. I cannot understand why the ntp service won't work. I scourged the internet, nobody seems to have this particular issue (all have a malfunctioning dns, but mine is working)

My read-only setup is the following: https://hallard.me/raspberry-pi-read-only/

Do you guys have any idea?

Best Answer

I found this question while facing a similar issue.

The issue turned out to be that systemd's PrivateTmp feature does not work in a read-only configuration.

  1. Be sure to install ntp and ntpdate
    sudo apt install -y ntp ntpdate
    
  2. Copy /lib/systemd/system/ntp.service to /etc/systemd/system/ntp.service

    cp /lib/systemd/system/ntp.service /etc/systemd/system/ntp.service
    
  3. Open /etc/systemd/system/ntp.service and comment out PrivateTmp=true.

    sudo nano /etc/systemd/system/ntp.service
    

Now, it should work correctly!

As an additional step I have also now mounted /var/lib/ntp as tmpfs as recommended here

  1. Open /etc/fstab and add tmpfs /var/lib/ntp tmpfs nosuid,nodev 0 0 at the end of file.
    sudo nano /etc/fstab
    

I didn't find this necessary in my case but there are additional insights into running on a read-only filesystem there.

Related Question