Score:0

Set the date automatically after VM unpauses

cn flag

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.

Score:0
cn flag

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
mirabilos avatar
cn flag
Sorry, no, the guest clock is controlled by OpenNTPD in the guest. Changing that to host-controlled is out of scope (and possibly wrong).
John Mahowald avatar
cn flag
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
mirabilos avatar
cn flag
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.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.