详细讲解麻烦的Ubuntu时间设置

系统 Linux
每次安装Ubuntu的时候,Ubuntu时间设置总是一个比较麻烦的事情,除了选时区之外,会被UTC和本地时间弄得头大。还有之前装双系统的时候,会出现Windows时间和Linux时间相差8小时的问题。

在向大家详细介绍Ubuntu时间设置之前,首先让大家了解下Linux时间相差,然后全面介绍Ubuntu时间设置,希望对大家有用。Ubuntu 团队对它的使用者公开的承诺:Ubuntu 永远免费 , 并且对于 "企业版本" 没有任何额外的费用, 在同样的自由团队上,将最好的工作成果带给每一个人。

Ubuntu时间设置

每次安装Ubuntu的时候,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和系统时间都使用本地时间。
首先Ubuntu时间设置区:
sudo dpkg-reconfigure tzdata

然后查看系统时间和bios时间:
date; hwclock --show

之后的操作稍微有点技巧,需要判断bios时间比本地时间早还是晚,一般而言,bios时间很可能被设置成UTC了,也就是说会比本地时间晚8小时,那么此时可以用下面的命令把Ubuntu时间设置系统先设置成bios(按照UTC显示的)时间对应的本地时间:
sudo hwclock --localtime --hctosys

再次用 date; hwclock --show 查看会发现当前系统时间被改变了(正确改变成当前时间),但是bios时间仍然不变。

此时再把系统时间写到bios时间上,注意这里的hwclock 不再使用 --localtime 选项:
sudo hwclock --systohc

以上的步骤可以重复使用,最终达到效果。如果觉得麻烦,应该可以直接用 hwclock --set 来对Ubuntu时间设置,不过我没有尝试过。

【编辑推荐】

  1. Ubuntu Linux系统的分区方案
  2. 查看Ubuntu VirtualBox服务器配置
  3. Ubuntu服务系统控制的基础知识
  4. 启用Ubuntu FrameBuffer系统编辑文件
  5. 网络安装Ubuntu设置虚拟机
责任编辑:佚名 来源: CSDN
相关推荐

2010-06-17 13:30:22

Grub修复工具

2009-12-22 10:34:18

静态路由协议

2009-12-01 18:35:22

阿尔法路由器设置

2011-04-07 15:53:39

2009-11-09 17:55:17

2013-01-10 15:36:44

Android开发组件Intent

2009-04-03 08:21:37

AndroidGoogle移动OS

2019-08-13 16:10:38

UbuntuLinux时间同步

2023-09-06 12:49:31

系统Ubuntu

2010-03-11 09:36:10

Ubuntu Xwin

2009-11-26 14:30:16

2010-03-16 16:03:52

Ubuntu vsft

2011-06-14 15:39:46

单元测试

2010-05-17 16:31:04

IIS Request

2023-03-17 08:11:25

2010-04-29 10:15:01

Unix系统

2010-06-17 12:57:27

如何修复Grub

2009-12-14 11:29:19

Linux查看命令

2009-09-25 17:03:29

Hibernate是什

2010-03-11 15:32:48

点赞
收藏

51CTO技术栈公众号