我使用 ArchLinux,并且我的系统时间已经出现好几个月的问题了。
以前它可以工作,但是一旦我更新了我的 PC,系统时间就会在每次启动时发生变化(就像它没有检测时区,而 rc.conf 中的时区是正确的)。
然后我添加了 hwclock,结果还是一样,然后删除了它。如果我没记错的话,这似乎解决了问题。
当我所在国家的夏令时发生变化时,每次启动时时间都会偏移 1 小时(无论我手动或通过 ntpdate 设置系统时间多少次)。
我再次尝试修复此问题,现在它与以前一样有许多小时的偏移(偏移值是 UTC 和本地时间的差值)。现在,似乎我的系统时间无法更改。我使用和设置时间date -s ...
……ntpdate pool.ntp.org
但这些措施似乎在重启后不会持续。我尝试运行 hwclock 守护程序、运行 ntpd,但 DAEMONS 中没有运行它们。我对此真的很困惑。
我很少使用 Windows。我知道启动 Windows 会导致 Linux 系统时间出现问题。但这不是我的问题。每次启动 Windows 和 Linux 时,我都可以手动或 ntpdate 命令重置系统时间。所以你可以假设我的机器上没有任何 Windows。
我只希望我的系统时间正常工作,而不是自动更改(通过 ntp 或其他方式),只需在需要时手动设置(手动或 ntpdate 命令)。请帮忙。
这是我的 rc.conf
#
# /etc/rc.conf - Main Configuration for Arch Linux
#
# -----------------------------------------------------------------------
# LOCALIZATION
# -----------------------------------------------------------------------
#
# LOCALE: available languages can be listed with the 'locale -a' command
# DAEMON_LOCALE: If set to 'yes', use $LOCALE as the locale during daemon
# startup and during the boot process. If set to 'no', the C locale is used.
# HARDWARECLOCK: set to "", "UTC" or "localtime", any other value will result
# in the hardware clock being left untouched (useful for virtualization)
# Note: Using "localtime" is discouraged, using "" makes hwclock fall back
# to the value in /var/lib/hwclock/adjfile
# TIMEZONE: timezones are found in /usr/share/zoneinfo
# Note: if unset, the value in /etc/localtime is used unchanged
# KEYMAP: keymaps are found in /usr/share/kbd/keymaps
# CONSOLEFONT: found in /usr/share/kbd/consolefonts (only needed for non-US)
# CONSOLEMAP: found in /usr/share/kbd/consoletrans
# USECOLOR: use ANSI color sequences in startup messages
#
LOCALE="en_US.UTF-8"
DAEMON_LOCALE="no"
HARDWARECLOCK="UTC"
TIMEZONE="Asia/Tehran"
KEYMAP="us"
CONSOLEFONT=
CONSOLEMAP=
USECOLOR="yes"
# -----------------------------------------------------------------------
# HARDWARE
# -----------------------------------------------------------------------
#
# MODULES: Modules to load at boot-up. Blacklisting is no longer supported.
# Replace every !module by an entry as on the following line in a file in
# /etc/modprobe.d:
# blacklist module
# See "man modprobe.conf" for details.
#
MODULES=(wl vboxdrv)
# Udev settle timeout (default to 30)
UDEV_TIMEOUT=30
# Scan for FakeRAID (dmraid) Volumes at startup
USEDMRAID="no"
# Scan for BTRFS volumes at startup
USEBTRFS="no"
# Scan for LVM volume groups at startup, required if you use LVM
USELVM="no"
# -----------------------------------------------------------------------
# NETWORKING
# -----------------------------------------------------------------------
#
# HOSTNAME: Hostname of machine. Should also be put in /etc/hosts
#
HOSTNAME="ilius-vostro3300"
# Use 'ip addr' or 'ls /sys/class/net/' to see all available interfaces.
#
# Wired network setup
# - interface: name of device (required)
# - address: IP address (leave blank for DHCP)
# - netmask: subnet mask (ignored for DHCP) (optional, defaults to 255.255.255.0)
# - broadcast: broadcast address (ignored for DHCP) (optional)
# - gateway: default route (ignored for DHCP)
#
# Static IP example
# interface=eth0
# address=192.168.0.2
# netmask=255.255.255.0
# broadcast=192.168.0.255
# gateway=192.168.0.1
#
# DHCP example
# interface=eth0
# address=
# netmask=
# gateway=
interface=
address=
netmask=
broadcast=
gateway=
# Setting this to "yes" will skip network shutdown.
# This is required if your root device is on NFS.
NETWORK_PERSIST="no"
# Enable these netcfg profiles at boot-up. These are useful if you happen to
# need more advanced network features than the simple network service
# supports, such as multiple network configurations (ie, laptop users)
# - set to 'menu' to present a menu during boot-up (dialog package required)
# - prefix an entry with a ! to disable it
#
# Network profiles are found in /etc/network.d
#
# This requires the netcfg package
#
#NETWORKS=(main)
# -----------------------------------------------------------------------
# DAEMONS
# -----------------------------------------------------------------------
#
# Daemons to start at boot-up (in this order)
# - prefix a daemon with a ! to disable it
# - prefix a daemon with a @ to start it up in the background
#
# If something other takes care of your hardware clock (ntpd, dual-boot...)
# you should disable 'hwclock' here.
#
DAEMONS=(syslog-ng dbus wicd)
## REMOVED: netfs network crond hwclock
## ADDED: dbus networkmanager sshd nfs-common bluetooth samba httpd postgresql IBSng starcal2d wicd
答案1
Ilius,我想我以前遇到过这个问题。
- 首先尝试正确设置系统时间。(ntp/whatever)
- 然后,运行
hwclock --systohc
这会将您的 hwclock 重置为系统时间,并且在重启后保持不变。
如果成功的话你会告诉我们吗?
答案2
过时
以下解决方案适用于较旧的、未安装 systemd 的 Arch Linux 安装。我将其留在这里以供历史参考。
过时
您在 rc.conf 中将 HARDWARECLOCK 设置为 UTC。我认为这就是罪魁祸首。如果您在 Windows 上双启动,则应将其设置为“localtime”(请参阅 arch 安装文档 IIRC)。
导致问题的另一个原因可能是启动脚本混乱,因为 arch 应该在启动/关闭期间执行“--hctosys”和“--systohc”。
在 Linux 中,您必须区分系统时钟(我们称之为 SC)和硬件时钟 (HC)。它们是分开的,但又相互关联。SC(实时)中的时间是通过了解 HC 的设置方式(本地时间或 UTC)以及系统时区来计算的。在 Windows 中无需计算 - HC 值就是 SC 值。因此,如果 UTC 与您的本地时间不同,Linux 会将 HC 设置为 UTC 并且 Linux SC 显示正确的时间,而 Windows 将显示乱码。相反,如果 Windows 的时间设置正确并且 Linux 将 HC 设置为 UTC,则 Linux 的 SC 显示的时间会“偏移”。解决方案是让 Linux 将 HC 设置为本地时间(HARDWARECLOCK="localtime")。