- 主题:systemd的时区是怎么确定下来的?
在系统启动时,记录的时间是比中国时区更快8个小时的。然后systemd意识到时区不对,把后续内容改回正确的了。但我还是想请教一下这里面的细节,意识到时区不对之前到底发生了什么?
感觉这种错误只有在(localtime指向中国时区&&RTC为UTC时区)的条件下才能产生。但正式rootfs里的情况是:localtime指向中国时区、RTC为LOCAL;initramfs里俩设置均不存在,应该按UTC处理。
/var/log/messages日志:
Mar 14 02:15:40 systemd: Stopped dracut initqueue hook.
Mar 14 02:15:40 systemd: Stopped udev Coldplug all Devices.
Mar 14 02:15:40 systemd: Stopped target Paths.
Mar 14 02:15:40 systemd: Stopped target Slices.
Mar 14 02:15:40 systemd: Starting Plymouth switch root service...
Mar 14 02:15:40 systemd: Stopped target Local File Systems.
Mar 14 02:15:40 systemd: Started Cleaning Up and Shutting Down Daemons.
Mar 14 02:15:40 systemd: Stopped udev Kernel Device Manager.
Mar 14 02:15:40 systemd: Stopped dracut pre-udev hook.
Mar 14 02:15:40 systemd: Stopped dracut cmdline hook.
Mar 14 02:15:40 systemd: Stopped Create Static Device Nodes in /dev.
Mar 14 02:15:40 systemd: Stopped Create list of required static device nodes for the current kernel.
Mar 14 02:15:40 systemd: Closed udev Control Socket.
Mar 14 02:15:40 systemd: Closed udev Kernel Socket.
Mar 14 02:15:40 systemd: Starting Cleanup udevd DB...
Mar 14 02:15:40 systemd: Started Cleanup udevd DB.
Mar 14 02:15:40 systemd: Reached target Switch Root.
Mar 14 02:15:40 systemd: Started Plymouth switch root service.
Mar 14 02:15:40 systemd: Starting Switch Root...
Mar 14 02:15:40 systemd: Switching root.
Mar 14 02:15:40 journal: Journal stopped
Mar 13 18:15:41 journal: Runtime journal is using 8.0M (max allowed 256.0M, trying to leave 4.0G free of 125.3G available → current limit 256.0M).
Mar 13 18:15:41 systemd-journald[776]: Received SIGTERM from PID 1 (systemd).
Mar 13 18:15:41 systemd[1]: RTC configured in localtime, applying delta of 480 minutes to system time.
Mar 13 18:15:41 systemd[1]: Inserted module 'autofs4'
Mar 13 18:15:41 kernel: ip_tables: (C) 2000-2006 Netfilter Core Team
Mar 13 18:15:41 systemd[1]: Inserted module 'ip_tables'
Mar 13 18:15:41 journal: Journal started
Mar 13 18:15:41 systemd: systemd 219 running in system mode. (+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +X
Z +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD +IDN)
Mar 13 18:15:41 systemd: Detected architecture x86-64.
/etc/localtime指向Asia/Shanghai
/etc/adjtime内容:
0.0 0 0.0
0
LOCAL
timedatectl命令:
Local time: Sat 2021-03-13 22:44:30 CST
Universal time: Sat 2021-03-13 14:44:30 UTC
RTC time: Sat 2021-03-13 22:49:29
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: yes
DST active: n/a
Warning: The system is configured to read the RTC time in the local time zone.
This mode can not be fully supported. It will create various problems
with time zone changes and daylight saving time adjustments. The RTC
time is never updated, it relies on external facilities to maintain it.
If at all possible, use RTC in UTC by calling
'timedatectl set-local-rtc 0'.
hwclock --show --debug命令:
hwclock from util-linux 2.23.2
Using /dev interface to clock.
Last drift adjustment done at 0 seconds after 1969
Last calibration done at 0 seconds after 1969
Hardware clock is on local time
Assuming hardware clock is kept in local time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2021/03/13 22:49:43
Hw clock time : 2021/03/13 22:49:43 = 1615646983 seconds since 1969
Sat 13 Mar 2021 10:49:43 PM CST -0.203822 seconds
把initramfs展开之后,发现没有/etc/adjtime文件、/etc/localtime文件、/usr/share/zoneinfo/ 整个目录
--
FROM 119.123.205.*
hwclock说能读到RTC啊
【 在 Dazzy (大懒虫,脱焦省却磨皮) 的大作中提到: 】
: 可能因为某些原因,systemd以为rtc时间为utc时区, 直到ntpd之类的介入。
: 我感觉有点像某些没有rtc的嵌入式设备,启动初始时间为系统编译生成时间,直到ntpd起来才更正。
: --来自微水木3.5.10
: ...................
--
FROM 113.89.11.*
localtime和adjtime这俩文件到底是怎么生效的?
【 在 ilovecpp (cpp) 的大作中提到: 】
: 你的疑问是在initramfs里,日志时间似乎是UTC+16(RTC+8),这个8或者16是哪里来的,对吧?
: 其实日志记录的不是localtime,而是(系统认为的)UTC。在initramfs里,假定UTC=RTC。之后根据你的设置,调整为UTC=RTC-8。
: 你在journalctl里看见localtime,那是journalctl根据当前时区设定实时转换的。你可以试试sudo timedatectl set-timezone UTC,再journalctl, 看看是不是所有时间都变了。
: ...................
--
FROM 113.89.11.*