0

I’ve got virtual machines (with Debian or occasionally *buntu guests, GNU/Linux) running in libvirt/qemu/kvm, and I have discovered the feature to pause/unpause a VM.

After unpausing (virsh resume), the guest clock is, obviously, off. How can I trigger a call to, say, /usr/sbin/rdate when the VM unpauses to do a one-shot update (openntpd will do the rest later)?

I have acpi-support-base installed on the guests so virsh shutdown works cleanly, but neither dmesg nor syslog show any events being triggert from pausing/unpausing.

mirabilos
  • 737
  • 1
  • 7
  • 22

1 Answers1

0

Fortunately you found this obvious, wrong time on VM resume causes lots of confusion...

Ensure host time is accurate, configure hosts to use the same NTP servers that the rest of your devices do.

Install the qemu-guest-agent in the guest. Attach the host to the guest's VirtIO serial channel. Resume or virsh domtime now can control guest clock.

Or, load ptp_kvm kernel module into Linux guests. chrony can then use PTP to get precise time from the host.

echo ptp_kvm > /etc/modules-load.d/ptp_kvm.conf
echo "refclock PHC /dev/ptp0 poll 2" >> /etc/chrony.conf
John Mahowald
  • 32,050
  • 2
  • 19
  • 34
  • Sorry, no, the guest clock is controlled by OpenNTPD in the guest. Changing that to host-controlled is out of scope (and possibly wrong). – mirabilos Feb 17 '22 at 18:23
  • Feel free to write your own resume hook if you want to do something else. This host sync thing is how some libvirt scripts do it when SYNC_TIME=1 https://github.com/libvirt/libvirt/blob/v8.0.0/tools/libvirt-guests.sh.in – John Mahowald Feb 17 '22 at 18:49
  • I can trigger it easily manually (`ssh vmname sudo rdate -nv ntp.example.com`), but I thought the VM was getting some (ACPI?) signals, like when `virsh shutdown` is run, and could do that itself. – mirabilos Feb 17 '22 at 19:09