- 主题: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.*
rsyslog有带时区的日志格式,远程记录日志并以日志服务器的时间为准,就没时间错误了。我是把所有设备的日志汇总在日志服务器上。
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006619] ACPI: OEM0 0x000000003FFF1CC0 000064 (v01 VRTUAL MICROSFT 12001807 MSFT 00000097)
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006621] ACPI: SRAT 0x000000003FFF0800 000110 (v02 VRTUAL MICROSFT 00000001 MSFT 00000001)
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006623] ACPI: APIC 0x000000003FFF0300 000072 (v01 VRTUAL MICROSFT 12001807 MSFT 00000097)
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006624] ACPI: OEMB 0x000000003FFFF040 000064 (v01 VRTUAL MICROSFT 12001807 MSFT 00000097)
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006629] ACPI: Local APIC address 0xfee00000
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006730] Zone ranges:
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006731] DMA [mem 0x0000000000001000-0x0000000000ffffff]
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006731] DMA32 [mem 0x0000000001000000-0x000000003ffeffff]
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006732] Normal empty
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006733] Movable zone start for each node
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006733] Early memory node ranges
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006734] node 0: [mem 0x0000000000001000-0x000000000009efff]
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006735] node 0: [mem 0x0000000000100000-0x000000003ffeffff]
2021-03-07T01:54:37+08:00 sever2 kernel: [ 0.006737] Zeroed struct page in unavailable ranges: 114 pages
--
修改:poocp FROM 118.122.107.*
FROM 118.122.107.*
可能因为某些原因,systemd以为rtc时间为utc时区, 直到ntpd之类的介入。
我感觉有点像某些没有rtc的嵌入式设备,启动初始时间为系统编译生成时间,直到ntpd起来才更正。
【 在 JulyClyde 的大作中提到: 】
: 在系统启动时,记录的时间是比中国时区更快8个小时的。然后systemd意识到时区不对,把后续内容改回正确的了。但我还是想请教一下这里面的细节,意识到时区不对之前到底发生了什么?
: 感觉这种错误只有在(localtime指向中国时区&&RTC为UTC时区)的条件下才能产生。但正式rootfs里的情况是:localtime指向中国时区、RTC为LOCAL;initramfs里俩设置均不存在,应该按UTC处理。
:
: ...................
--来自微水木3.5.10
--
FROM 119.129.237.*
RTC UTC NTP都不涉及时区,只有IP和时区相关
我一直不用systemd,不知道它干了什么怎么做的
【 在 Dazzy 的大作中提到: 】
: 可能因为某些原因,systemd以为rtc时间为utc时区, 直到ntpd之类的介入。
: 我感觉有点像某些没有rtc的嵌入式设备,启动初始时间为系统编译生成时间,直到ntpd起来才更正。
--
FROM 45.77.108.*
你的疑问是在initramfs里,日志时间似乎是UTC+16(RTC+8),这个8或者16是哪里来的,对吧?
其实日志记录的不是localtime,而是(系统认为的)UTC。在initramfs里,假定UTC=RTC。之后根据你的设置,调整为UTC=RTC-8。
你在journalctl里看见localtime,那是journalctl根据当前时区设定实时转换的。你可以试试sudo timedatectl set-timezone UTC,再journalctl, 看看是不是所有时间都变了。
【 在 JulyClyde 的大作中提到: 】
: 在系统启动时,记录的时间是比中国时区更快8个小时的。然后systemd意识到时区不对,把后续内容改回正确的了。但我还是想请教一下这里面的细节,意识到时区不对之前到底发生了什么?
: 感觉这种错误只有在(localtime指向中国时区&&RTC为UTC时区)的条件下才能产生。但正式rootfs里的情况是:localtime指向中国时区、RTC为LOCAL;initramfs里俩设置均不存在,应该按UTC处理。
: /var/log/messages日志:
: ...................
--
FROM 114.86.90.*
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.*
systemd pid1(initramfs外面那个)一启动就直接设置了。你找不到哪个service运行了hwclock对吧,hardcode在systemd进程里了:
https://cgit.freedesktop.org/systemd/systemd/tree/src/core/main.c?id=8cf030b349cbcb0901d880c9165d785dfc9cd569#n1292
【 在 JulyClyde 的大作中提到: 】
: localtime和adjtime这俩文件到底是怎么生效的?
--
修改:ilovecpp FROM 114.86.90.*
FROM 114.86.90.*