[systemd-devel] systemd and hardware real time clock

Michał Zegan webczat_200 at poczta.onet.pl
Thu Feb 9 15:14:49 UTC 2017



W dniu 09.02.2017 o 15:52, Lennart Poettering pisze:
> On Tue, 17.01.17 12:29, Michał Zegan (webczat_200 at poczta.onet.pl) wrote:
> 
>> Hello.
>>
>> I am aware of the fact that systemd relies on the kernel to set system
>> clock from hardware clock, and that requires compiling rtc drivers into
>> the kernel, not as modules.
>> I am also aware that doing it othervise would mix timestamps in log entries.
>> The question is: if I have rtc driver as a module anyway, how to modify
>> initramfs so that system time would be set, in such a way so that it
>> happens *before* journald in initramfs starts? I assume it is an
>> initramfs using systemd inside of it.
>> One approach would be to have an udev rule that does trigger after rtc
>> appears or rtc symlink is added, this rule would start a service that
>> sets the system clock, but this service would have to always run before
>> journald, and that seems not possible in such a configuration, because
>> if someone would unplug the rtc the service would not run?
>> Another thing is to load rtc and i2c bus module where rtc is connected
>> statically without udev detection, and then the hwclock service would
>> always be triggered before journald without looking for rtcs appearing...
> 
> Well, you could write a tool that uses libudev but listens on the
> kernel mcast group instead of the udev one, and then, as soon as the
> RTC showed up would do the /dev/thing. Then, make a service of it,
> make sure to use StandardOutput=null + StandardError=null, so that you
> don't get an implicit dependency on journald, and order the service
> before journald.
> 
> Lennart
> 
Btw, about the argument that the kernel should set rtc time because of
wrong timestamps in logs, so I should compile the rtc into the kernel:
let's compare: if I read rtc time during bootup (and rtc is a module),
timestamps would be bad indeed for some time.
But one case is, what if there is no rtc? then the kernel cannot read
the clock. Neither can startup scripts or systemd (if it would ever
try). so log timestamps would be invalid for far longer, until time is
synchronized from network, and that will never happen if there is no
network. So I still think that systemd could do it, or, better,
initramfs could do it to make all real system logs have a  valid
timestamp, like not sure if initramfs logs are important for anything if
there were no boot issues.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 525 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20170209/9018ad2d/attachment.sig>


More information about the systemd-devel mailing list