I am using Centos 7 with kernel 3.10 and have hwclock and chrony installed and running. It is written that system clock is set from hardware clock on boot time. (here http://tldp.org/HOWTO/Clock-2.html)

“The other is the "system clock" (sometimes called the "kernel clock" or "software clock") which is a software counter based on the timer interrupt. It does not exist when the system is not running, so it has to be initialized from the RTC (or some other time source) at boot time.”

and that it could be set by init script (which was substituted by systemd) or by kernel itself (here https://wiki.gentoo.org/wiki/System_time):

“Typically the hardware clock is used to setup the system clock on boot. This can be done by the kernel itself or by a boot service (init script).”

Althought it is later mentioned that on modern kernel (article seems a bit outdated) Linux handle this itself (here https://wiki.gentoo.org/wiki/System_time).

“On a sufficiently modern kernel (3.9 or newer), Linux can be configured to handle setting the system time automatically.”

I checked /var/log/dmesg file and this seems to be my case, i.e. kernel itself set system clock from RTC on boot.

2.596137] rtc_cmos 00:00: setting system clock to 2018-05-08 14:49:58 UTC (1525790998)

Although there are number of information concerning boot time I found very few info (and quite controversial, as for me) on shutdown time. It is written (here https://wiki.gentoo.org/wiki/System_time) that system clock is set back to RTC on shutdown. Because on boot system time is set by the kernel I guessed that kernel could be responsible for setting system time back to RTC on shutdown but could not find any certain information on it.

So my questions are: whether time is really set from system clock back to RTC on shutdown or there can be some exceptions to this? (exceptions maybe like kernel version or special flags) And if so, who is responsible for this, kernel or a script?

By the way I read the question Relationship between hardware clock and system clock but my question is a bit more specific and so different.

// ----------------------------------------------------------------------------------------------------------------// My question is on hold so i am writing here

according to the bug discussion here (although a bit old)(https://bugzilla.redhat.com/show_bug.cgi?id=753487) RTC is set to system time on shutdown indeed and it is done by the kernel

hwclock --systohc used be called on every shutdown, but it's not anymore.

Reassigning to kernel.

So seems that the questions concerning setting system time values to RTC are solved.

closed as too broad by DavidPostill May 9 '18 at 11:25

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • It seems that i found the answer to my question. according to the bug discussion here (although a bit old)(bugzilla.redhat.com/show_bug.cgi?id=753487) RTC is set to system time indeed and it is done by the kernel – Dmitriy Kormulev May 9 '18 at 15:49
  • Be aware that any answer you find is distribution specific. IOW these operations are initiated in userspace, and not under control of the Linux kernel. "it is done by the kernel" -- Of course I/O is "done" by the kernel, but at the request from userspace. – sawdust May 10 '18 at 8:51
  • sawdust thank you for your answer. You wrote that "Of course I/O is "done" by the kernel, but at the request from userspace.", do you mean that special flag has to be set by a user in order to enable this kernel "I/O" (in our case RTC to system time)? – Dmitriy Kormulev May 10 '18 at 14:37
  • No, there's no "special flag". I/O is requested by userspace by simply issuing a read() or write() request, which invokes a system call to the kernel. The RTC is simply another peripheral, and the kernel is responsible for performing I/O with all peripherals (except for some abnormal/atypical devices). – sawdust May 11 '18 at 0:10