1

I'm trying to start systemd-timesyncd on Archlinux that was installed via Distrod on top of WSL. By default systemd-timesyncd's unit file prevents it from starting up on virtualized environment, the unit file has a ConditionVirtualization=!container flag. I'm trying to override this with the following configuration:

[root@valentine ~]# systemd-detect-virt
wsl
[root@valentine ~]# cat /etc/systemd/system/systemd-timesyncd.service.d/override.conf
[Unit]
ConditionVirtualization=wsl
[root@valentine ~]# systemctl daemon-reload
[root@valentine ~]# systemctl start systemd-timesyncd.service
[root@valentine ~]# systemctl status systemd-timesyncd.service
○ systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/usr/lib/systemd/system/systemd-timesyncd.service; enabled; preset: enabled)
    Drop-In: /etc/systemd/system/systemd-timesyncd.service.d
             └─override.conf
     Active: inactive (dead)
  Condition: start condition failed at Mon 2023-02-27 10:38:46 CET; 6s ago
             └─ ConditionVirtualization=!container was not met
       Docs: man:systemd-timesyncd.service(8)

Feb 27 10:38:46 valentine systemd[1]: Network Time Synchronization was skipped because of an unmet condition check (ConditionVirtualization=!container).

It seems like systemd is picking p the override configuration, yet, it doesn't seem to use the overridden configuration flag.

What's the best way to solve this issue and have systemd-timesyncd run in a virtualized envrionment?

Zizzencs
  • 153
  • 1
  • 5

1 Answers1

7

I had exactly the same issue and came across this answer which helped me. It turns out that ConditionVirtualization takes a list of entries and must be cleared before it can be changed.

I used sudo systemctl edit systemd-timesyncd to create the drop-in file with this contents:

[Unit]
ConditionVirtualization=
ConditionVirtualization=wsl

And now it works as expected:

~ >sudo systemctl status systemd-timesyncd
● systemd-timesyncd.service - Network Time Synchronization
     Loaded: loaded (/etc/systemd/system/systemd-timesyncd.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/systemd-timesyncd.service.d
             └─override.conf
     Active: active (running) since Wed 2023-03-01 14:31:05 EST; 1s ago
       Docs: man:systemd-timesyncd.service(8)
   Main PID: 8816 (systemd-timesyn)
     Status: "Initial synchronization to time server 137.184.81.69:123 (0.arch.pool.ntp.org)."
      Tasks: 2 (limit: 19001)
     Memory: 1.4M
     CGroup: /system.slice/systemd-timesyncd.service
             └─8816 /lib/systemd/systemd-timesyncd

Mar 01 14:31:05 gnantel systemd[1]: Starting Network Time Synchronization...
Mar 01 14:31:05 gnantel systemd[1]: Started Network Time Synchronization.
Mar 01 14:31:02 gnantel systemd-timesyncd[8816]: Initial synchronization to time server 137.184.81.69:123 (0.arch.pool.ntp.org).

I also did a sudo systemctl daemon-reload to be safe but when editing using systemctl it is not supposed to be necessary.

Gerard
  • 86
  • 2
  • Also, we could have just cleared the list. I just came across this approach here: https://github.com/microsoft/WSL/issues/8204#issuecomment-1338334154 – Gerard Mar 01 '23 at 19:56
  • Thank you. This solution works. Lesson learned here: don't try to use systemd intuitively, read the docs instead. Thank you again. – Zizzencs Mar 02 '23 at 09:37