HCS: enable Hyper-V time sync and a UTC hardware clock so guests keep correct time
Have instances on the hcs driver keep the correct time at boot and immediately after resume, including on hosts without internet access.
Today, the HCS compute system Multipass creates enables only the Shutdown and Heartbeat integration services, and leaves the virtual RTC in local time. As a result:
- Guests boot with the wrong clock. The RTC holds the host's local time, while Linux reads it as UTC. On a UTC+3 host the guest starts 3 hours ahead (
rtc_cmos ... setting system clock to 12:49:59 UTCwhen the real time was 09:49 UTC). It stays wrong untilsystemd-timesyncdreaches an NTP server; the first sync steps the clock back by ~10,800s. - Guests fall behind after every resume. With no time-sync channel, nothing corrects the clock when an instance resumes from a saved state (including suspend-on-destruct). It stays behind by however long it was suspended, until the next successful NTP sync.
- Offline hosts never recover. Without NTP access, both offsets persist indefinitely. That affects TLS certificate checks, apt, cloud-init, and log timestamps.
What's your proposed solution?
Enable the Hyper-V time synchronization integration service and set the virtual RTC to UTC in hcs_create_compute_system_params.cpp:
"Chipset": {
"UseUtc": true, // schema 2.1+
"Uefi": { ... }
},
...
"Services": {
"Shutdown": {},
"Heartbeat": {},
"Timesync": {} // schema 2.5+, same as Shutdown/Heartbeat
}Both fields are from the HCS schema reference. Services.Timesync gives the guest's hv_utils driver a time-sync channel: Hyper-V sets the guest clock at start and on restore, and keeps it in sync while running. Chipset.UseUtc makes the RTC match what Linux expects, which also fixes the first second of boot before hv_utils loads.
Tested on a local build (Windows 11 Pro 26200, host UTC+3, Ubuntu 24.04 guest, kernel 6.8.0-142), with systemd-timesyncd disabled for the resume test so only Hyper-V could correct the clock:
| Current | Timesync |
Timesync + UseUtc |
|
|---|---|---|---|
| Guest time-sync channel | none | hv_utils: TimeSync IC version 4.0 |
same |
| RTC read at boot | 3 h ahead | 3 h ahead | correct |
| Guest − host UTC after launch | +3 h until NTP | 0.0 s | 0.0 s |
| After a 3-minute suspend, NTP disabled | behind by the suspend time | 0.0 s (clock set | |
| +183.9 s on resume) | 0.0 s (+184.0 s) |
Source: canonical/multipass