5

It seems I am unable to set up permanent time on my Raspberry Pi 3 with Ubuntu LTS. I tried:

sudo timedatectl set-ntp 0
sudo timedatectl set-time "2018-09-17 18:17:16"
sudo timedatectl set-timezone Europe/Paris
sudo timedatectl set-local-rtc 0

And I also tried using the date command, but after reboot, the time resets. What could be the cause of that?

My Raspberry Pi is offline so I cannot use an NTP server to synchronise.

2 Answers 2

9

The Pi doesn't have a hardware clock, so any time you set will not be persisted on reboot. Instead, the system might reset to a default (possibly Unix timestamp 0, i.e. 1970-01-01) when it reboots because it has no way to know the actual time.

There are a few ways to work around the fact that there's no hardware real-time clock (RTC) built in to the Pi:

  • Use NTP. You've stated this isn't an option for you, though, so this can be ruled out.

  • Buy a real-time clock for use with the Pi, such as this Mini RTC for about £5. You'll likely be able to find similar products and perhaps some cheaper if you're willing to buy the components yourself and connect it all up.

  • Use fake-hwclock. This isn't a real solution in the sense that it won't actually keep the time correctly. But recent Raspbian images include fake-hwclock, which saves the time to a file on shutdown, and reloads it from that file on reboot.

    If your Pi has been shut down for days, this is obviously going to be way out of sync with the actual time. However, it does at least ensure that there is no discontinuity and time doesn't jump backwards, which may upset some system tools which expect time to only move forwards.

    Likely Ubuntu doesn't have fake-hwclock pre-installed, but you can get it from the Ubuntu repositories, most likely (try sudo apt install fake-hwclock).

Realistically if you need permanent time, you're going to have to buy a real-time clock, otherwise you'll need to set the time on every restart.

1

You said your pi is "offline"- which could mean it's just firewalled from the Internet but otherwise connected to at least a local network.

I proxy NTP access to my devices via the router. Let me explain:

My Pi's do NOT get their time set by talking to NTP servers on the Internet- the ROUTER itself is their NTP server. Only the router has external UDP/123 connectivity to external NTP servers to set its' time correctly. In the DHCP config of the router assigning IPs to the Pi's I then specify the router's interface for the Pi's subnet as their NTP server. Below are some illustrative pictures from both the router's side and inside a Pi at end of this post.

Such a config allows the Pi's to keep correct time while ring-fenced from the 'Net. This is also more bandwidth efficient than have a gazillion things querying external NTP servers on the 'Net.

DHCP config Looks like this:Router DHCP Settings

Inside the Pi the file storing our NTP server config is found here: File Pi Uses for NTP servers:

When we open the file, we see the NTP server is the Router's interface for the Pi's subnet: Inside the file

So Pi gets correct time without talking on the Internet.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.