4

I have an Ubuntu 9.10 server running as a KVM host with ntpd installed on it. The host system has the correct system time. At the moment I only have a single KVM guest, also Ubuntu 9.10 server. I do not have ntpd installed on it, and I just discovered the clock is about 6 minutes slow. It wasn't that way when it was installed about a month ago.

I thought that I only needed to keep the host clock synchronized and that the guests used the host clock. But maybe that is a memory from using OpenVZ. I believe the reasoning was related to only the host could modify the physical system clock.

Is running ntpd on both the host and all the guests the correct thing to do? Or is there something else that is preferred? How should I keep the guest clocks in sync?

Tauren
  • 739
  • 4
  • 14
  • 24

5 Answers5

4

Check what clocksource that you are using:

$ cat /sys/devices/system/clocksource/clocksource0/current_clocksource

Check which ones that are available:

$ cat /sys/devices/system/clocksource/clocksource0/available_clocksource

If you got a "kvm-clock" entry in "available_clocksource" try to use it by setting kernel parameter:

clocksource=kvm-clock

Pretty good document here (general) why it's so tricky to get the clock right.

rkthkr
  • 8,618
  • 28
  • 38
  • @rkthkr: looks like current_clocksource is already set to kvm-clock, but the guest is still minutes off from the host. – Tauren Apr 14 '10 at 15:28
1

A chrony instance per VM with short interval poll updates from local NTP server(s) seems to be the only viable-reasonable way to go.

Although chrony can broadcast time updates across LAN, it doesn't support listening to such updates and there're no plans to add it. Unicast is recommended with such a comment: "…

Even with very modest hardware, an NTP server can serve time to hundreds of thousands of clients using the ordinary client/server mode.

…"

poige
  • 9,448
  • 2
  • 25
  • 52
0

I've encountered numerous problems with timekeeping in VMs, and across several different virtualization platforms, I've also had problems with the native Host-VM time sync tools.

My advice is to have an authoritative source of time that is based on a physical piece of hardware (in this case, your KVM host server) and sync your VMs using the standard OS time sync methods (in your case, ntpd) back to that server. Often a shorter resync interval is necessary if the vm guests are drifting excessively. In short, I think you're on the right track with ntpd.

As an example on VMWare, we found that the VMWare Tools time sync will only correct time if it drifts backwards on the VMs. It wouldn't correct the time if a VM got ahead of its host.

Chris Thorpe
  • 9,953
  • 23
  • 33
0

There are reports that kvm-clock causes time jumps (measured in hours) and may even cause system freezes. You may have to disable it, like so:

https://patchwork.kernel.org/patch/104597/ (either the patch itself, or LD_PRELOAD wrapper kvm-noclock).

sendmoreinfo
  • 1,772
  • 13
  • 34