Date/time setting commands from inside a container only affect the container (as they should).
Using timedatectl set-time “2024-01-31 11:13:54”
from inside a container will work on the container only if the container uses systemd for life-cycle management or if the host’s systemd socket is exposed to the container using --privileged --volume /run/dbus/system_bus_socket:/run/dbus/system_bus_socket
(which is not recommended).
I suppose you ran this command from the host (not the container):
dmesg | grep rtc print following
[ 1.461967] imx-sc-rtc scu:rtc: registered as rtc1
[ 1.653132] rtc-ds1307: probe of 1-0068 failed with error -5
The first response is to registering the SoC’s built-in secure RTC. The second response indicate that it tried to probe a DS1307 RTC chip which does not seem to be present. That is an external RTC chip which would be on a carrier board as it is not on the SoM. Your platform then probably has only one RTC which is /dev/rtc1
. You can check with
# ls -l /dev/rtc*
lrwxrwxrwx 1 root root 4 Mar 21 04:42 /dev/rtc -> rtc0
crw------- 1 root root 251, 0 Mar 21 04:42 /dev/rtc0
crw------- 1 root root 251, 1 Mar 21 04:42 /dev/rtc1
# dmesg |grep rtc
[ 0.222372] snvs_rtc 30370000.snvs:snvs-rtc-lp: registered as rtc1
[ 0.299625] rtc-ds1307 0-0032: oscillator failed, set time!
[ 0.300339] rtc-ds1307 0-0032: registered as rtc0
[ 0.302462] rtc-ds1307 0-0032: hctosys: unable to read the hardware clock
The above output is from a Verdin i.MX8MP SoM on a Verdin development carrier board which has a DS1307. There is no battery inserted, hence the RTC is not set when the kernel boots (error messages oscillator failed, set time!
and hctosys: unable to read the hardware clock
). The RTC still works though as systemd-timedated sets it (in this case from a network time server as the board is connected to a network with NTP server):
# timedatectl
Local time: Fri 2024-03-22 18:30:48 UTC
Universal time: Fri 2024-03-22 18:30:48 UTC
RTC time: Fri 2024-03-22 18:30:48
Time zone: Universal (UTC, +0000)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
Using sudo hwclock -w --verbose
by default uses the /dev/rtc
device which is typically a link to the actual RTC device (see above). The output suggests that your platform has the /dev/rtc1
device but no /dev/rtc
link.
You can either create the link or use sudo hwclock -w --verbose -f /dev/rtc1
.
It is typically not necessary to manually sync the RTC from system time and vice versa as the kernel does that on startup and shutdown. Also timedatectl, more accurately systemd-timedated, synchronizes the RTC (but also using /dev/rtc
).
The kernel uses these configs to determine how to synchronize the RTC:
CONFIG_RTC_HCTOSYS=y
CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
CONFIG_RTC_SYSTOHC=y
CONFIG_RTC_SYSTOHC_DEVICE="rtc0"
The former two indicate to the kernel to sync system time from RTC using rtc0 on startup. The latter two indicate to sync RTC from system time on shutdown using rtc0. They are enabled and set by the Torizon kernel config.