Linux
VERIFIED FIXES

Ubuntu 22.04 LXC container clock jumps forward after host resume, cron misses jobs and ACME renewal fails

jonasfixar
1mo ago
Environment

Environment

Proxmox host running Ubuntu 22.04 LTS with LXC containers (systemd inside), host suspends (S3) on a laptop and resumes; container OS is also Ubuntu 22.04 with systemd-timesyncd.

Symptoms

Symptoms

After host resume, container system clock advanced by several minutes to hours compared to host; scheduled cron jobs inside container didn't run at expected times; cert renewals using certbot failed due to time skew.

Observations

Observations

host time is correct; container /proc/driver/rtc shows different RTC offset. journalctl in container shows a sudden time jump at resume time. systemd-timesyncd attempts to step back but is configured not to step large offsets, leaving container clock drifted. Host uses RTC hardware driver that LXC doesn't forward by default.

Already attempted

Already attempted

Restarted systemd-timesyncd inside container (temporary resync), mbind host NTP settings to container namespaces, attempted to mount /etc/localtime from host into container — no persistent fix. Rebooting container fixes time until next host suspend/resume.

Question

Question

How can I prevent LXC containers from jumping their clocks after the host suspends/resumes, ensuring cron and ACME renewals remain reliable without rebooting containers?

COMMUNITY RESPONSES

Verified community troubleshooting

1 reply
0
theocode Answer
user
Posted 1mo ago • 0 confirmations

Make containers use the host wall-clock and let timesync take small corrective steps after resume. Bind-mount the host RTC into the container (/dev/rtc) or allow the device in the container config, then set systemd-timesyncd to permit stepping on large offsets (or add a host resume hook that nsenter+restarts timesyncd inside containers). Verify by suspending/resuming host and checking container 'timedatectl' and cron execution. Changes are reversible: remove the device bind or restore previous timesyncd config if you need to revert.

Showing 1 of 1 community responses
AI DIAGNOSTICS

Incident analysis

Updated 1mo ago• Trouble ID

Most likely causes

Container systemd-timesyncd refuses to step large clock jumps; container sees stale RTC/timestamps after host resume 80%
LXC configuration isolates or provides an inconsistent /dev/rtc or pts time source leading to divergent realtime inside container 60%
Host kernel TSC/clocksource switch on resume not propagated into container namespaces causing monotonic/realtime mismatch 35%

Summary

LXC containers inherit the host kernel clock namespace but may use virtualized RTC or have systemd behavior that ignores large steps. On resume, the host kernel time advances, but container userland sees differing RTC/time-source offsets (e.g., /dev/rtc or adjtime). systemd inside containers can refuse to step time if it's outside allowed bounds, leaving internal monotonic vs realtime mismatch. Common fixes: make container use host's realtime clock (mount /dev/rtc or /dev/ptp0), ensure systemd is allowed to step large offsets (configure TimeSync/Timezone settings), or run a small on-resume hook on the host to nsenter into containers to force an ntp sync. Also confirm kernel tick behavior and TSC stability flags.

Suggested Fixes

Diagnostic step 1
Configure containers to use host clock devices: in LXC config add lxc.cgroup.devices.allow for /dev/rtc and bind-mount /dev/rtc into container; test resume behavior.
Diagnostic step 2
Enable host-side resume hook that runs 'nsenter -t $(pidof systemd) -m -- systemctl restart systemd-timesyncd' for each container (or run timed 'ntpdate' inside containers) — reversible and safe.
Diagnostic step 3
Adjust systemd-timesyncd in containers: allow-step=true and lower the MaximumInitialClockDistance to permit stepping on large offsets; test on a single container.

Continue troubleshooting

Matched from the title, description and tags