NTP: without hwclock, save time regularily for next reboot

1

I'm running ntpd on an ARM board that doesn't have a hardware clock (so no way to maintain time when it's off).

The problem is that after rebooting, the time is always set at the unix epoch until ntpd is able to sync again.

What I would like is for ntpd to regularly save the current time in a file, and reapply it on the next system boot. It won't be accurate, but at least it doesn't bring me back to the unix epoch on every reboot.

It doesn't necessarily have to be ntpd, maybe another software (or even kernel side?) can do this ?

Worst case scenario I can always have an init.d script do this, but I'm thinking that this is already implemented somewhere in a proper way.

Ely

Posted 2017-11-29T15:18:58.113

Reputation: 1 378

What OS are you running? – user1686 – 2017-11-29T15:35:02.807

poky - a linux-based distribution compiled from scratch by yocto. – Ely – 2017-11-29T15:58:13.833

Answers

2

Install the fake-hwclock program:

# apt-get install fake-hwclock


fake-hwclock: Save/restore system clock on machines without working RTC hardware

 Some machines don't have a working realtime clock (RTC) unit, or no
 driver for the hardware that does exist. fake-hwclock is a simple set
 of scripts to save the kernel's current clock periodically (including
 at shutdown) and restore it at boot so that the system clock keeps at
 least close to realtime. This will stop some of the problems that may
 be caused by a system believing it has travelled in time back to
 1970, such as needing to perform filesystem checks at every boot.

 On top of this, use of NTP is still recommended to deal with the fake
 clock "drifting" while the hardware is halted or rebooting.

With fake-hwclock installed your machine will not start up thinking it is 1970 all over again. When your machine boots up it will set its clock to the timestamp fake-hwclock wrote during the last reboot/shutdown. This means you can have a somewhat correct clock in case there are network issues when you boot up.

dfc

Posted 2017-11-29T15:18:58.113

Reputation: 657

Thanks ! I don't have an apt-based system so I took it from the source: https://git.einval.com/cgi-bin/gitweb.cgi?p=fake-hwclock.git

– Ely – 2017-12-05T10:34:17.210