1

The situation:

  • We have some Linux VMs running compute jobs.
  • The VMs do not have Internet access (including NTP).
  • The hypervisor does know the correct time.
  • The hypervisor's time is exposed to the VM via its hardware clock.
  • The hypervisor seems to be QEMU/KVM-based. We do not control the hypervisor (it is a cloud VPS offering).

The problem:

  • The VMs' system clock drifts away from the correct time / hardware clock.

The question:

  • Is it possible to keep the system clock synchronized to the hardware clock at all times?

  • Alternatively, is it possible to tell e.g. ntpd to account for system clock drift, using the hardware clock as reference?

What I tried:

  • A 0 * * * * hwclock --hctosys cronjob, however, the drift is significant enough that even hourly synchronization is insufficient, and increasing the cronjob frequency seems like a workaround at this point.
4
  • Can the host machine serve the clock via NTP to the VMs? My old cluster was configured to have three machines which accessed the network and established a local authoritative time, and all the other nodes in the cluster only accessed these three. Wiht a host and VMs you can forget the three cooperating and just have the one master.
    – user516667
    Apr 7, 2022 at 16:38
  • Depending on the VM subsystem you should be able to lock the VM clocks to the hypervisor. Please can you edit your question to identify the virtualisation solution you're using Apr 7, 2022 at 16:49
  • @Martin No, I suppose we could adjust infrastructure to allow NTP but I was hoping for a local-only solution which wouldn't involve that. Unfortunately we don't control the hypervisor so it would mean allowing network access just for this in some form or another. Apr 7, 2022 at 16:54
  • @roaima Done. And thanks! :) Apr 7, 2022 at 16:55

1 Answer 1

0

[I'm working from memory here so I will try to check this later.]

QEMU/KVM virtual machines can synchronise their clock to the host through the virtualisation layer.

Here's how you confirm that your guest is using the host:

cat /sys/devices/system/clocksource/clocksource0/current_clocksource
kvm-clock

If it doesn't return that value kvm-clock you need to load the paravirtualisation clock module in your client, part of the virtio kernel modules.

Do not run ntpd (or any other external synchronisation) if your VM is synchronising with the host.

2
  • 1
    I am also getting the value kvm-clock there. However, the system and hardware clocks still do drift apart. Apr 7, 2022 at 19:37
  • I'll look on our systems Apr 7, 2022 at 20:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .