普段からVMwareを使ってるけど、ゲストOS(Linux)の時計がずれて困る。
前から気になっていたんだけど、今回本格的に対処した。

対処前の状況

VMware VMware Workstation 5.5.8 build-108000
ホストOS Microsoft Windows XP Version 5.1.2600
ゲストOS CentOS release 5.3 (Final) 2.6.18-128.1.6.el5 #1 SMP Wed Apr 1 09:19:18 EDT 2009 i686 i686 i386 GNU/Linux

ゲスト側のCPUは1個。
VMware Toolsはインストールしていない。
webサーバなのでXサーバもインストールしていない。

ズレを確認したところ、1秒あたり約0.9秒ずつズレる。

$ while [ 1 ]; do ntpdate 192.168.1.1; sleep 1; done
 3 Apr 02:37:38 ntpdate[1950]: step time server 192.168.1.1 offset 20.431010 sec
 3 Apr 02:37:40 ntpdate[1952]: step time server 192.168.1.1 offset 0.915439 sec
 3 Apr 02:37:42 ntpdate[1954]: step time server 192.168.1.1 offset 0.818392 sec
 3 Apr 02:37:44 ntpdate[1956]: step time server 192.168.1.1 offset 0.844005 sec
 3 Apr 02:37:46 ntpdate[1958]: step time server 192.168.1.1 offset 0.908437 sec
 3 Apr 02:37:48 ntpdate[1960]: step time server 192.168.1.1 offset 0.913891 sec
 3 Apr 02:37:50 ntpdate[1962]: step time server 192.168.1.1 offset 0.901554 sec

対処後の状況

$  while [ 1 ]; do ntpdate 192.168.1.1; sleep 1; done
 3 Apr 03:24:13 ntpdate[1955]: step time server 192.168.1.1 offset -3.405978 sec
 3 Apr 03:24:15 ntpdate[1957]: adjust time server 192.168.1.1 offset 0.000038 sec
 3 Apr 03:24:16 ntpdate[1959]: adjust time server 192.168.1.1 offset -0.000055 sec
 3 Apr 03:24:17 ntpdate[1961]: adjust time server 192.168.1.1 offset 0.000004 sec
 3 Apr 03:24:18 ntpdate[1963]: adjust time server 192.168.1.1 offset -0.000037 sec
 3 Apr 03:24:19 ntpdate[1965]: adjust time server 192.168.1.1 offset -0.000003 sec
 3 Apr 03:24:20 ntpdate[1967]: adjust time server 192.168.1.1 offset -0.000029 sec

ほとんどずれなくなった!

対処内容

/boot/grub/grub.confを書き換えてboot時オプションの最後にdivier=10を加える。

$ cat /boot/grub/grub.conf

# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
#          initrd /initrd-version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.18-128.1.6.el5)
        root (hd0,0)
        kernel /vmlinuz-2.6.18-128.1.6.el5 ro root=/dev/VolGroup00/LogVol00 divider=10
        initrd /initrd-2.6.18-128.1.6.el5.img

VMware Toolsをインストールする。
VMwareのメニューから VM > Install VMware Tools…

$ mount /dev/cdrom /mnt
$ rpm -ivh /mnt/VMwareTools-5.5.8-108000.i386.rpm
準備中...                ########################################### [100%]
   1:VMwareTools            ########################################### [100%]

ちゃんと入ってるか確認

$ chkconfig --list | grep vmware
vmware-tools    0:off   1:off   2:on    3:on    4:off   5:on    6:off

でシャットダウン。

$ shutdown -h 0

対象VMの.vmxファイルのtools.syncTime"TRUE"に編集する。

tools.syncTime = "TRUE"

VMを起動して完了。

対処の解説

最近のLinux kernelはタイマ割り込みが1000Hzになっている。しかし、VMwareはそんな割り込み頻度に対応できるわけもなく、100Hzを想定して作ってあるらしい。
そこで、タイマ割り込みをVMwareが想定する100Hzにしてやれば問題は解決する。
最新のRed Hat Enterprise Linux 4 とRed Hat Enterprise Linux 5はこの頻度をdividerオプションで制御できるようになっている。
Red Hat Enterprise LinuxクローンであるCentOSももちろんオプションで制御できる。

ちなみに、dividerオプションは割り込み頻度を割るときの係数となるので1000Hz / 10 = 100Hz
となる。じつは、これだけでも結構いい精度になるんだけど、やっぱり少しずれる。
VMware Toolsをインストールするのが面倒な人はbootオプションの対処だけでも十分かもしれない。

tools.syncTime = "TRUE"についてはVMware Toolsに頑張ってもらってホストOSの時計と同期を取る設定。ホストOSの時計がズレてると悪化しそうなので諸刃の剣かもしれない。

参考URL

  • Timekeeping in VMware Virtual Machines

    The latest versions in both the Red Hat Enterprise Linux 4 and Red Hat Enterprise Linux 5 series include a divider= boot‐time option that can reduce the interrupt rate—for example, divider=10 reduces the interrupt rate to 100Hz.

    You can then turn on periodic synchronization from the graphical VMware Tools control panel within the guest operating system. Alternatively, you can set the .vmx configuration file option tools.syncTime = true to turn on periodic synchronization.

  • Clock Issue on WMware Sever 1.0.4

    As you have no X I would suggest that you edit the .vmx file of your guest. Add the line ‘tools.syncTime = “TRUE” ‘ to it.

カテゴリー: 技術情報