Ubuntu时间设置
2009-10-26 11:43
每次安装ubuntu的时候,时间设置总是一个比较麻烦的事情,除了选时区之外,会被UTC和本地时间弄得头大。还有之前装双系统的时候,会出现Windows时间和Linux时间相差8小时的问题。这里需要解决的问题是bios时间和系统时间的同步问题:在开机时,系统从bios获得时间;关机时,系统向bios写回时间。出现相差8小时的问题猜测是因为UTC和本地时间相差8小时(我们处在东八区)。
可以用hwclock来同步。hwclock常用选项如下: Usage: hwclock [function] [options...] Functions: --show read hardware clock and print result --set set the rtc to the time given with --date --hctosys set the system time from the hardware clock --systohc set the hardware clock to the current system time --adjust adjust the rtc to account for systematic drift since the clock was last set or adjusted Options: --utc the hardware clock is kept in coordinated universal time --localtime the hardware clock is kept in local time --date specifies the time to which to set the hardware clock 我的目标是为了实现bios和系统时间都使用本地时间。 首先设置时区: sudo dpkg-reconfigure tzdata 然后查看系统时间和bios时间: date; hwclock --show 之后的操作稍微有点技巧,需要判断bios时间比本地时间早还是晚,一般而言,bios时间很可能被设置成UTC了,也就是说会比本地时间晚8小时,那么此时可以用下面的命令把系统时间先设置成bios(按照UTC显示的)时间对应的本地时间: sudo hwclock --localtime --hctosys 再次用 date; hwclock --show 查看会发现当前系统时间被改变了(正确改变成当前时间),但是bios时间仍然不变。 此时再把系统时间写到bios时间上,注意这里的hwclock 不再使用 --localtime 选项: sudo hwclock --systohc 以上的步骤可以重复使用,最终达到效果。如果觉得麻烦,应该可以直接用 hwclock --set 来设置,不过我没有尝试过。
与服务器进行时间同步如:
sudo ntpdate 210.72.145.44
手动设置时间如:
2008年 09月 05日 星期五 23:01:30 CST sudo date 090523012008.30
|