diff --git a/src/linux/init/init.cpp b/src/linux/init/init.cpp index 229b51b..0611dda 100644 --- a/src/linux/init/init.cpp +++ b/src/linux/init/init.cpp @@ -329,6 +329,10 @@ int GenerateSystemdUnits(int Argc, char** Argv) File.reset(); } + // Mask systemd-networkd-wait-online.service since WSL always ensures that networking is configured during boot. + // That unit can cause systemd boot timeouts since WSL's network interface is unmanaged by systemd. + THROW_LAST_ERROR_IF(symlink("/dev/null", std::format("{}/systemd-networkd-wait-online.service", installPath).c_str()) < 0); + // Only create the wslg unit if both enabled in wsl.conf, and if the wslg folder actually exists. if (enableGuiApps && access("/mnt/wslg/runtime-dir", F_OK) == 0) { diff --git a/test/windows/UnitTests.cpp b/test/windows/UnitTests.cpp index 8d4d670..7a2624a 100644 --- a/test/windows/UnitTests.cpp +++ b/test/windows/UnitTests.cpp @@ -211,6 +211,12 @@ class UnitTests auto revert = EnableSystemd(); VERIFY_IS_TRUE(IsSystemdRunning(L"--system")); + + // Validate that systemd-networkd-wait-online.service is masked. + auto [out, _] = + LxsstuLaunchWslAndCaptureOutput(L"systemctl status systemd-networkd-wait-online.service | grep -iF Loaded:"); + + VERIFY_ARE_EQUAL(out, L" Loaded: masked (Reason: Unit systemd-networkd-wait-online.service is masked.)\n"); } TEST_METHOD(SystemdUser)