LoginSignup
1
1

More than 1 year has passed since last update.

【VirtualBox】Linuxの時刻がずれる場合の対応

Posted at

概要

VirtualBoxでLinuxのVMを起動したままホストOSであるWindowsをスリープにすると、Windowsをスリープから復帰させた時にLinux上の時刻がずれている。

環境

  • Windows10
  • VirtualBox 6.1
    • OS:CentOS Linux 7 (x86-64)

時刻の修正方法

まずは現在時刻の確認

$ timedatectl
      Local time: 水 2022-07-27 22:16:18 JST
  Universal time: 水 2022-07-27 13:16:18 UTC
        RTC time: 火 2022-07-26 18:19:40
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: yes
NTP synchronized: no
 RTC in local TZ: no
      DST active: n/a

NTP enabledはyesになっていますが、NTP synchronizedがnoになっています。ちなみに現在時刻は2022-07-28 14:53(JST)です。

chronyを再起動

NTP synchronizedをyesにするために、chronyを再起動します。

$ sudo systemctl restart chronyd

ずれが少ない場合(感覚的には1日未満)は割とすぐに直りますが、盛大にずれているとすぐに直らないことが多いです。その場合でも、しばらく待つと大体は直ります。

$ timedatectl
      Local time: 木 2022-07-28 14:54:55 JST
  Universal time: 木 2022-07-28 05:54:55 UTC
        RTC time: 火 2022-07-26 18:23:02
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

RTC timeを修正する

Local timeとUniversal timeは直りましたが、まだRTC timeがずれているので直します。

$ sudo hwclock --systohc

$ timedatectl
      Local time: 木 2022-07-28 15:04:38 JST
  Universal time: 木 2022-07-28 06:04:38 UTC
        RTC time: 木 2022-07-28 06:04:38
       Time zone: Asia/Tokyo (JST, +0900)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

Universal timeとRTC timeが同時刻になったのでOKです。

chronyを再起動しても直らない場合

仕方ないのでサーバーごと再起動してます(笑)

参考

CentOS7での時刻修正chronyd
Linuxで時刻設定後、ハードウェア再起動後や電源投入後に日時ずれが生じる場合の対応

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1