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