For machines with broken rtcs and dead mobo batteries booting is a chore -- if the clock appears to be set to a ridiculous time, (in my case, 1988), it results in lots of filesystem checks and superfluous warnings. This set of tweaks for both baselayout 1 and 2 writes to a file called /etc/SHUTDOWNTIME at /etc/init.d/(hw)clock stop time, and then on reboot uses that file's mtime to set the system time, bypassing the broken hwclock. This tool should work for both openrc and bl1. I haven't quite worked out all the kinks, but here it is for now... Reproducible: Always Steps to Reproduce:
Created attachment 193125 [details] setsystimefromfile.c This is the core program -- it just grabs the mtime of /etc/SHUTDOWNTIME
Created attachment 193126 [details, diff] clock.init_settimefromfile.patch This is a patch for bl1's clock initscript. It should be set to run before * to prevent unnecessary fscks, but so far I can't get the rc dependency resolution to do that. Still working on it...
/etc/conf.d/clock just needs an additional line added to turn the other two programs on: # If your Hardware Clock resets during reboots # set this to "yes" to use the mtime of a file # to set your System Clock and prevent warnings. # (It will cause CLOCK_SYSTOHC to be ignored.) SETTIMEFROMFILE="yes" (Oh, and finally, I forgot to mention I put the compiled C program in /sbin/settimefromfile. Obviously, if you change that you'd have to change the initscript to suit.)
kojiro: For bl2, as I described, make an init script using hwclock as a template, but give it a new name.
yes, please create a new init.d script (i'd suggest "swclock") that only operates on this file and use /var/lib/swclock as the default location
vapier: I was suggesting /.clock or something in /etc/ as /var might not be available.
hmm, is it safe for the default location to be in /var? FHS aside, this should run before localmount (or its openrc equivalent, if different), so /var might not be available, right? That's why I chose /etc...
/var/lib/ makes more sense, but it has the problems you guys highlight. so a default path of /etc/ is fine.
Michael A. Smith: Did you implement this as a new swclock package?
I can roll this directly into OpenRC and store the file in the same place as the depcache if there's any interest.
roy: yes please, there's a bunch of embedded gear coming up without RTC chips where it would be really handy. (re)boot with stored timestamp, then hit NTP as soon as possible. should prevent the backwards time "jump" appearance.
http://roy.marples.name/projects/openrc/changeset/a8f6a9b6540ca301af625b4767df53860511a6dc It's up to the user to remove hwclock and add swclock to the runlevel of choice - maybe even to the sysinit runlevel?
forcing users to change the init scripts is fine by me
roy: why did you drop 'provide clock' from swclock compared to hwclock.in? I'm fine with making user add it to the sysinit runlevel themselves.
Reopening because 'provide clock' is critical so that scripts with 'need clock' are happy and don't try to start hwclock.
(In reply to comment #14) > roy: > why did you drop 'provide clock' from swclock compared to hwclock.in? > I'm fine with making user add it to the sysinit runlevel themselves. Honest answer - I cut one line too many! It's been added back now.
Thanks, closing (and looking forward to this in the next release for some embedded hardware myself).