詳細(xì)講解麻煩的Ubuntu時(shí)間設(shè)置
在向大家詳細(xì)介紹Ubuntu時(shí)間設(shè)置之前,首先讓大家了解下Linux時(shí)間相差,然后全面介紹Ubuntu時(shí)間設(shè)置,希望對(duì)大家有用。Ubuntu 團(tuán)隊(duì)對(duì)它的使用者公開(kāi)的承諾:Ubuntu 永遠(yuǎn)免費(fèi) , 并且對(duì)于 "企業(yè)版本" 沒(méi)有任何額外的費(fèi)用, 在同樣的自由團(tuán)隊(duì)上,將最好的工作成果帶給每一個(gè)人。
Ubuntu時(shí)間設(shè)置
每次安裝Ubuntu的時(shí)候,Ubuntu時(shí)間設(shè)置總是一個(gè)比較麻煩的事情,除了選時(shí)區(qū)之外,會(huì)被UTC和本地時(shí)間弄得頭大。還有之前裝雙系統(tǒng)的時(shí)候,會(huì)出現(xiàn)Windows時(shí)間和Linux時(shí)間相差8小時(shí)的問(wèn)題。這里需要解決的問(wèn)題是bios時(shí)間和系統(tǒng)時(shí)間的同步問(wèn)題:在開(kāi)機(jī)時(shí),系統(tǒng)從bios獲得時(shí)間;關(guān)機(jī)時(shí),系統(tǒng)向bios寫(xiě)回時(shí)間。出現(xiàn)相差8小時(shí)的問(wèn)題猜測(cè)是因?yàn)閁TC和本地時(shí)間相差8小時(shí)(我們處在東八區(qū))。
可以用hwclock來(lái)同步。hwclock常用選項(xiàng)如下:
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
我的目標(biāo)是為了實(shí)現(xiàn)bios和系統(tǒng)時(shí)間都使用本地時(shí)間。
首先Ubuntu時(shí)間設(shè)置區(qū):
sudo dpkg-reconfigure tzdata
然后查看系統(tǒng)時(shí)間和bios時(shí)間:
date; hwclock --show
之后的操作稍微有點(diǎn)技巧,需要判斷bios時(shí)間比本地時(shí)間早還是晚,一般而言,bios時(shí)間很可能被設(shè)置成UTC了,也就是說(shuō)會(huì)比本地時(shí)間晚8小時(shí),那么此時(shí)可以用下面的命令把Ubuntu時(shí)間設(shè)置系統(tǒng)先設(shè)置成bios(按照UTC顯示的)時(shí)間對(duì)應(yīng)的本地時(shí)間:
sudo hwclock --localtime --hctosys
再次用 date; hwclock --show 查看會(huì)發(fā)現(xiàn)當(dāng)前系統(tǒng)時(shí)間被改變了(正確改變成當(dāng)前時(shí)間),但是bios時(shí)間仍然不變。
此時(shí)再把系統(tǒng)時(shí)間寫(xiě)到bios時(shí)間上,注意這里的hwclock 不再使用 --localtime 選項(xiàng):
sudo hwclock --systohc
以上的步驟可以重復(fù)使用,最終達(dá)到效果。如果覺(jué)得麻煩,應(yīng)該可以直接用 hwclock --set 來(lái)對(duì)Ubuntu時(shí)間設(shè)置,不過(guò)我沒(méi)有嘗試過(guò)。
【編輯推薦】