RTC沒有時區(qū)--實際案例

概要

前述已有三篇文章介紹了RTC沒有時區(qū),此文用實際案例來說明一起RTC設置對于系統(tǒng)啟動時的時間戳的影響。

案例

Jun 26 16:14:15 localhost journal: Avahi client failure: Daemon connection failed
Jun 26 16:14:15 localhost systemd: Stopping OpenSSH server daemon...
Jun 26 16:14:15 localhost systemd: Stopping ABRT kernel log watcher...
Jun 26 16:14:15 localhost systemd: Stopped Daily Cleanup of Temporary Directories.
Jun 26 16:14:15 localhost systemd: Stopped Resets System Activity Logs.
Jun 26 16:14:15 localhost systemd: Stopping GNOME Display Manager...
Jun 26 16:14:15 localhost systemd: Stopping VDO volume services...
Jun 26 16:14:15 localhost systemd: Stopping irqbalance daemon...
Jun 27 00:15:47 localhost kernel: Initializing cgroup subsys cpuset
Jun 27 00:15:47 localhost kernel: Initializing cgroup subsys cpu
Jun 27 00:15:47 localhost kernel: Initializing cgroup subsys cpuacct
Jun 27 00:15:47 localhost kernel: Linux version 3.10.0-1160.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Mon Oct 19 16:18:59 UTC 2020
Jun 27 00:15:47 localhost kernel: Command line: BOOT_IMAGE=/vmlinuz-3.10.0-1160.el7.x86_64 root=/dev/mapper/centos-root ro crashkernel=auto spectre_v2=retpoline rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet LANG=en_US.UTF-8
Jun 27 00:15:47 localhost kernel: e820: BIOS-provided physical RAM map:
Jun 27 00:15:47 localhost kernel: BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable
Jun 27 00:15:47 localhost kernel: BIOS-e820: [mem 0x00000000000a0000-0x00000000000fffff] reserved
Jun 27 00:15:47 localhost kernel: BIOS-e820: [mem 0x0000000000100000-0x00000000a5c03fff] usable

Jun 26 16:15:52 localhost systemd[1]: RTC configured in localtime, applying delta of 480 minutes to system time.

案例分析

1、從linux系統(tǒng)日志可看到,系統(tǒng)在20230621 10:51發(fā)生了重啟,但系統(tǒng)重啟時候時間戳比原機器時間多了8個小時。
2、等系統(tǒng)起來后,從日志可看到時間恢復正常。
原因有兩點:
1、該機器的RTC被設置為了localtime,因此系統(tǒng)的時間跟RTC的時間在數(shù)值上是相同的。如下所示:
[root@localhost ~]# timedatectl
Local time: Mon 2023-06-26 18:18:59 CST
Universal time: Mon 2023-06-26 10:18:59 UTC
RTC time: Mon 2023-06-26 18:18:59
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'.
2、當linux系統(tǒng)啟動時(這個時候可以理解系統(tǒng)的時間服務還未完全啟動),linux系統(tǒng)仍然會認為RTC為UTC,所以linux系統(tǒng)在啟動之前的時間戳在RTC的時間數(shù)值上+8,體現(xiàn)在日志上就是時間多了8個小時。
3、等待系統(tǒng)完全啟動后,linux系統(tǒng)時間服務已經(jīng)起來,這個時候linux系統(tǒng)知道了應該把RTC認為localtime,所以系統(tǒng)時間恢復正常。見如下日志條目:
Jun 26 16:15:52 localhost systemd[1]: RTC configured in localtime, applying delta of 480 minutes to system time.
4、8*60minutes=480minutes。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容