1.9 KiB
Setting Up NTP in a Guest
I read on the Internet, so it must be true, that a kvm guest defaults to a clock source of "kvm-clock", which sets the guest's TSC clock to the host's. But this is at boot, and the guest then runs a virtual TSC from boot on out. This can yield poor results. To see what clocking is being used,
$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
which, in the default configuration, yields "kvm-clock", meaning that the guest's TSC was set to the host's TSC when the guest booted, and has been drifting on the virtual sea ever since. This is not a good thing.
So, setting up ntpd is advised, at least if you want better than the average time source.
First, you need to install NTP, which also starts it
$ apt-get install ntp
Though not absolutely necessary, I also like to have a known stratum-1 in the configuration, so I add the following line to /etc/ntp.conf
server my.strat.1
You then have to whack the NTP daemon so it sees the configuration change
$ service ntp restart
Wait a minute and then check that ntpd is OK
$ ntpq -p
There is one remaining problem. the ntp daemon is setting the guest TSC which conflicts with the kvm-clock syncing the TSC off the host's clock. To see what clocking is being used, try
$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
which should yield the default "kvm-clock". As you do not want this, to disable kvm-clock, you have to add
no-kvmclock
to the kernel grub invocation parameter list. After rebooting with the kernel config change
$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource
should show "tsc" as opposed to "kvm-clock". This is saying that the guest is using its internal TSC, a virtual hardware clock, which we have arranged to maintained by the ntpd daemon in the guest.