May 12

[原]hwclock获取不到Bios时间导致的时间变更问题 阴

linuxing , 17:33 , 基础知识 » 故障处理 , 评论(1) , 引用(0) , 阅读(29905) , Via 本站原创 | |
    某项目中,发现每次机器重启后,时间都比正常时间快了8个小时。但按[原]解决服务器重启后,时间自动变更的问题的方法处理,仍无法解决。后发现机器是IBM x3850 M2的,在使用hwclock从BIOS读、往BIOS写会失败:
引用
# hwclock -r
select() to /dev/rtc to wait for clock tick timed out
# clock
select() to /dev/rtc to wait for clock tick timed out

这时,必须加入--directisa参数才能成功。故怀疑问题原因是系统启动时,无法从BIOS获取正确的时间导致。

一、关于系统时钟
以下内容,转自:http://www.aixchina.net/?6878/viewspace-20222.html
引用
    计算机系统有两个时钟,一个是 BIOS(CMOS),或者说“硬件时钟”,还有一个就是“系统(操作系统)时钟”,如果这两个时钟的设置上有问题,或者Linux 的时钟配置文件不正确的话,就会产生系统时钟差 8 小时的问题。或读的是硬件时间,系统会把他当成UTC时间,然后自己加了8小时,得到他所认为的local time(本地时间)。
    Linux从BIOS获取是ijan,有3种模块:rtc/genrtc/rtc_dev,似乎是一个比一个新,有些Linux系统通常自己用的是rtc这个老模块;但Dell/ibm/acer等等厂商现在都可能使用新的BIOS,这种BIOS和这个rtc就可能不对付。
    clock 和hwclock不能使用,出现报错:select() to /dev/rtc to wait for clock tick timed out,原因是不能读取/dev/rtc,也就是硬件时间。这是因为某些机器的BIOS处理方式和Linux的rtc内核模块之间出现了问题。

二、解决
1、修改系统和BIOS时间
错误的本地时间:
引用
# date
四  5月 13 01:02:22 CST 2010

用下面的方法获取BIOS时间:
引用
# hwclock -r --directisa
2010年05月12日 星期三 17时02分30秒  -0.994525 seconds

※ 可见,若以BIOS时间为准,那么系统时间刚好多了8个小时。这是因为,系统在启动时会尝试从BIOS获取时间,若无法得到,则以系统的当前的时间作为UTC时间,因此,增加了8小时的时区时间。

设置正确的本地时间:
引用
# date -s '20100512 17:14'
三  5月 12 17:14:00 CST 2010

写入BIOS:
引用
# hwclock -w --directisa
# hwclock -r --directisa
2010年05月12日 星期三 17时14分40秒  -0.994525 seconds

2、修改配置文件,让系统启动时也带上参数运行
配置文件改为:
引用
# cat /etc/sysconfig/clock
ZONE="Asia/Beijing"
UTC=false
ARC=false
CLOCKFLAGS=--directisa

※ 注意,参数不要写成CLOCKFLAGS="--directisa"

三、补充
1、其他配置文件
上面链接中的资料提到,还需要修改两个地方,为hwclock加入参数:
引用
/etc/rc.sysinit
/etc/init.d/halt

实际上,在/etc/sysconfig/clock中加入的参数,在这些脚本中会自行导入,并不需设置。

2、IBM的说明
System time out by hours after boot - IBM System x
有两点需要注意的:
a、The issue is limited to the 32-bit version of the operating systems.
b、提供了一个不同的解决办法:
引用
Edit the file /boot/grub/menu.lst to add kernel boot options. The added boot options for single-chassis systems differ from those for multi-chassis systems:
○ On a single-chassis system append the "hpet=disable pnpacpi=off clock=tsc" boot options to the kernel command line.
○ On a multi-chassis system append the "hpet=disable pnpacpi=off" boot options to the kernel command line.

经测试,该方法也能解决上述问题。
Tags: ,
康盛博客 Email Homepage
2010/05/17 16:42
就一个clock也隐含着这么多的知识点,真是诧异呀...崇拜...
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]