To automatically update the time in your LineageOS 23.0 virtual machine (VM) after restoring a snapshot in Virtual Machine Manager (virt-manager) on Debian 13 GNOME, you need to ensure that the VM synchronizes its time with the host system. Here’s how to do it:
By default, QEMU/KVM provides a virtual hardware clock (RTC) and can synchronize the guest time with the host using the QEMU Guest Agent or NTP.
The QEMU Guest Agent allows the host to synchronize the guest's time.
Install the QEMU Guest Agent in the VM (LineageOS):
bashapt install qemu-guest-agent # If LineageOS supports apt (unlikely)
qemu-guest-agent, proceed to Option B.Enable the QEMU Guest Agent in virt-manager:
org.qemu.guest_agent.0Unix socketGuest agentConfigure the VM to use the host's time:
bashvirsh edit <vm-name>
<clock> section:
xml<clock offset="utc" synchronization="guest-agent"/>
If the QEMU Guest Agent is not available, use NTP to sync time.
Ensure the VM has internet access.
Install and enable an NTP client in LineageOS:
ntpd or chrony. If not, you may need to manually install it.bashapt install chrony # If supported
/etc/chrony/chrony.conf to include:
textserver pool.ntp.org iburst
bashchronyd
Force a time sync after restoring a snapshot:
bashchronyc makestep
bashsystemctl restart chrony
virsh to Set Time on RestoreIf the above methods fail, you can manually set the time after restoring a snapshot using virsh:
bashvirsh domtime <vm-name> --now
This forces the VM to sync its time with the host.
To automate the process, you can create a script that runs after restoring a snapshot.
bash#!/bin/bash VM_NAME="your-vm-name" # Restore the snapshot (replace with your snapshot name) virsh snapshot-revert $VM_NAME --snapshotname your-snapshot-name # Force time sync virsh domtime $VM_NAME --now # Start the VM if not running virsh start $VM_NAME
Save this as restore_and_sync.sh, make it executable (chmod +x restore_and_sync.sh), and run it whenever you restore a snapshot.
After restoring the snapshot and applying the above steps, check the time in the VM:
bashdate
It should match the host's time.
virsh domtimeqemu-guest-agent) may not be available. NTP is the most reliable method for Android-based VMs.timedatectl or ntp).Vibe can make mistakes. Check answers. Learn more