Gentoo 和 Windows 时钟同步

K*K posted @ Fri, 04 Jul 2008 21:55:00 +0800 in 技术 with tags linux windows clock register timezone , 3455 readers

Windows 时钟和 Linux 时钟其实都是分为了系统时钟和硬件时钟的,硬件时钟存储于 BIOS 内部,而系统时钟存储于内核里,这两者的区别是系统时钟往往具有时区功能,而这两种操作系统对于时钟的处理方式却是不一样的,Windows 的系统时钟与硬件时钟同步,而 Linux 系统中的硬件时钟往往是格林尼治时间(GMT),而系统时钟才是真正的本地时间。

这一区别导致了在双系统的电脑中,Windows 的时钟往往比 Linux 慢 8 个小时,如果 Linux 直接设置为本地时间(localtime),运行 date 命令时又会出现 Timezone should be set, see zic manual page 的提示,其实这是有办法解决的。

  • 第一种办法是使 Windows 使用 GMT 的硬件时钟,可以将下面内容另存为注册表文件(.reg)导入,或者直接在注册表编辑器(regedit)中修改:

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
         "RealTimeIsUniversal"=dword:00000001
  • 第二种办法是将 Linux 使用与硬件时钟同步的系统时钟,同时设置好时区

    首先设置好本地时区

    # zic -l Asia/Shanghai

    其次设置 /etc/conf.d/hwclock(Gentoo 的 Baselayout 2 OpenRC 系统),修改其中的 clock 字段:

    clock="local"
    修改为
    clock="GMT" # 是的,没有看错,虽然注释称双系统时设置需要设置成 local,但实际上只有设置成 GMT 时 Linux 才能将硬件时钟作为系统时钟使用。

Login *


loading captcha image...
(type the code from the image)
or Ctrl+Enter