fake-hwclock

Prevent system clock from going backward at startup

sudo fake-hwclock save|load [force]

boot time

When the systems boots, the fake-hwclock will set the system clock to the time it was last saved!.

This means that syslog entries and files modified (or accessed) will be timestamped with an old time/date, until the system clock is

  • updated using a battery backed up Real Time Clock
  • a network timeserver (ntp) server can be contacted.
  • the correct time is established by another means!

The default cron job /etc/cron.hourly/fake-hwclock) should be more frequently unless the system has a batterybacked up RTC!

save system clock to file with time later than fake-hwclock's release date.
With force saves any time.
load Slew the system clock forward to the time in the file.
With force move the system clock backwards or forwards.

Files

file to store the time /etc/fake-hwclock.data
2021-10-06 17:17:01
UTC
init script
run on startup and shutdown
/etc/init.d/fake-hwclock
NB fake-hwclock exits after save or load so invoking init script with
start does a load and
stop|reload|restart|force-reload actually issues a save
systemd service to run on startup and shutdown /lib/systemd/system/fake-hwclock.service
[Unit]
Description=Restore / save the current clock
Documentation=man:fake-hwclock(8)
DefaultDependencies=no
Before=sysinit.target systemd-fsck-root.service
Conflicts=shutdown.target

[Service]
EnvironmentFile=-/etc/default/fake-hwclock
ExecStart=/sbin/fake-hwclock load $FORCE
ExecStop=/sbin/fake-hwclock save
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=sysinit.target
Settings file for the init script. /etc/default/fake-hwclock
…
case "${1:-}" in
  stop|reload|restart|force-reload)
        echo "Stopping fake hwclock: saving system time."
        fake-hwclock save;;

  start)
        echo "Starting fake hwclock: loading system time."
        fake-hwclock load $FORCE ;;
…

Environment $VARIABLES

The settimng of $FORCE is usd by /lib/systemd/system/fake-hwclock.service

Set the file used by fake-hwclock $FILE

Errors

> sudo fake-hwclock load
Current system time: 2021-10-06 17:46:43     UTC
fake-hwclock saved clock information is in the past: 2021-10-06 17:17:0
To set system time to this saved clock anyway, use "force"
$? = 0

Return values

invalid command 1
Permission denied 2