8

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?

4
  • Am wondering if nscd being unable to write to its hosts cache, or ntp being unable to write to its drift file might be causing some of this woe. Commented Nov 24, 2019 at 22:28
  • 1
    Maybe. You want the catch? If I manually stop ntp and start it in command line: sudo ntp -c /etc/ntp.conf -n, it all works. The drift file has been moved to the /var/tmp folder that is a R/W tmpfs. Maybe nscd is a good lead, although the name resolution definitely works: getent hosts 0.debian.pool.ntp.org works fine. Commented Nov 24, 2019 at 22:31
  • 1
    My first thought was the drift file. Have you thought of using an overlayfs rather than entirely read only FS. This might give you some into what's being edited because the overlayfs upper layer would only contain edited files, while lower remains read-only en.m.wikipedia.org/wiki/OverlayFS Commented Nov 24, 2019 at 23:13
  • Perhaps run strace -f -o /tmp/ntp.trace -p 415(assuming you have /tmp mount r/w) and see if the failures give you some clues, or post it somewhere where we can look? Commented Nov 25, 2019 at 2:08

2 Answers 2

8

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.

2
  • This is great, I"ll try that. Thanks Mark Commented Apr 16, 2020 at 15:40
  • Per the ArchWiki for timedatectl: Note: The service writes to a local file /var/lib/systemd/timesync/clock with every synchronization. This location is hard-coded and cannot be changed. This may be problematic for running off read-only root partition or trying to minimize writes to an SD card. Commented Oct 3, 2023 at 22:10
3

Mark Roger's answer works, however I think it is better to user overrides:

echo -e '[Service]\nPrivateTmp=false' > /etc/systemd/system/ntp.service.d/override.conf

Then reboot or maybe systemctl daemon-reload is enough.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.