5

I have an embedded computer running Ubuntu Server 14.04 that has no CMOS battery (temporary, I hope) so it always boots to December 31, 2008 ... Currently I'm developing an application that depends on some installed hardware. I start Gnome from the command line to get a GUI for development.

When running in production mode it will not have an internet connection (or display etc.) but will have a GPS referenced NTS device on the local LAN.

When I started the machine this morning the internet connection was out so the files are way out of synch. Is there software utility that 'fakes' saving time so that successive boots will have reasonable, and increasing times?

degenerate
  • 436
  • 5
  • 21
Nate Lockwood
  • 189
  • 1
  • 1
  • 9

2 Answers2

3

If you can access the GPS output, each 1 second location update contains the current UTC time. To decode the time, here is a document detailing each gps sentence syntax.

jdh
  • 7,023
  • 17
  • 22
  • The device (not on the LAN at the moment) is a *Network Time Server* that uses GPS to keep track of time; it doesn't output NMEA. – Nate Lockwood Aug 27 '14 at 16:34
  • If I understand the problem, at boot up time you want to get the current time (or "fake it" by approximating the next boot time?). If the NTS is available, why not use that to get the time during the initial bootup? – jdh Aug 27 '14 at 17:07
  • NTS is not available from my device, the computer is new and I don't know how to set it up yet. – Nate Lockwood Aug 27 '14 at 17:16
  • Ok, we should probably remove mention of NTS from the description. So is the problem: the device has no connection and you just want to arbitrarily increment the time at each boot? How about a simple script in /etc/init.d that write a "last time" value to a file, and at next boot, sets the time to that value plus x minutes? – jdh Aug 28 '14 at 11:29
  • This only works if you contact the gps early in the boot sequence and I imagine you do not connect to gps early enough. fake-hwclock was made forthis type of problem – dfc Aug 30 '14 at 19:49
1

You want the fake-hwclock package. Description from the Debian package page:

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.

dfc
  • 747
  • 6
  • 11