Fix systemd-tmpfiles failure on systemd v261+ with systemd boot disabled (#41491)
In systemd v261, the systemd's tmpfiles.d/x11.conf was changed from D! to D. systemd/systemd@5474cad. This means the systemd-tmpfiles command will try to execute it when called out of the boot sequence. In the linked issue's case, it's called by the post install script by dpkg. This will fail as the wsl override is not in place when systemd is disabled. This PR enables the wsl override file generation for all distros with wslg enabled, regardless of if the distro boots with systemd.
Feng Wang committed
Sep 2, 2026 at 08:08 UTC
acf3319d8e6c67857c204fa17447c2cd530d7d18
3 files changed
+12
-6
src/linux/init/config.cpp
+7
@@ -616,6 +616,13 @@ try
616
if (WI_IsFlagClear(Config.FeatureFlags.value(), LxInitFeatureSystemDistro))
617
{
618
THROW_LAST_ERROR_IF(mount("none", socketPath, NULL, (MS_RDONLY | MS_REMOUNT | MS_BIND), NULL) < 0);
619
+
620
+ // Override the distro-provided x11.conf so systemd-tmpfiles does not try to modify the read-only mount.
621
+ THROW_LAST_ERROR_IF(UtilMkdirPath("/run/tmpfiles.d", 0755) < 0);
622
+ const std::string tmpFilesConfig =
623
+ "# Note: This file is generated by WSL to prevent systemd-tmpfiles from modifying /tmp/.X11-unix.\n";
624
+
625
+ THROW_LAST_ERROR_IF(WriteToFile("/run/tmpfiles.d/x11.conf", tmpFilesConfig.c_str(), O_WRONLY | O_CLOEXEC | O_CREAT | O_TRUNC) < 0);
626
}
627
}
628
CATCH_LOG()
src/linux/init/init.cpp
-6
@@ -381,12 +381,6 @@ ExecStop=-/bin/mount --make-rslave {})",
381
// Only create the wslg unit if both enabled in wsl.conf, and if the wslg folder actually exists.
382
if (enableGuiApps && access("/mnt/wslg/runtime-dir", F_OK) == 0)
383
{
384
- THROW_LAST_ERROR_IF(UtilMkdirPath("/run/tmpfiles.d", 0755) < 0);
385
- const std::string tmpFilesConfig =
386
- "# Note: This file is generated by WSL to prevent systemd-tmpfiles from removing /tmp/.X11-unix during boot.\n";
387
-
388
- THROW_LAST_ERROR_IF(WriteToFile("/run/tmpfiles.d/x11.conf", tmpFilesConfig.c_str()) < 0);
389
-
384
// Note: It's not possible to use a mount unit because systemd will not mount /tmp/.X11-unix
385
// if /proc/mount says it's already mounted.
386
test/windows/UnitTests.cpp
+5
@@ -2485,6 +2485,10 @@ Usage:
2485
VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"test -d /tmp/.X11-unix"), 0L);
2486
VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"socat - UNIX-CONNECT:/tmp/.X11-unix/X0 < /dev/null"), 0L);
2487
2488
+ // Validate that distro-provided tmpfiles rules cannot modify the read-only X11 mount.
2489
+ VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"test -f /run/tmpfiles.d/x11.conf"), 0L);
2490
+ VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"systemd-tmpfiles --create --boot x11.conf"), 0L);
2491
+
2492
// Validate the runtime dir exists and the wayland-0 socket is in the expected location.
2493
VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"env | grep XDG_RUNTIME_DIR="), 0L);
2494
VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"test -d $XDG_RUNTIME_DIR"), 0L);
@@ -2498,6 +2502,7 @@ Usage:
2502
auto [output, warnings] = LxsstuLaunchWslAndCaptureOutput(L"echo ok");
2503
VERIFY_ARE_EQUAL(L"ok\n", output);
2504
VERIFY_ARE_EQUAL(L"", warnings);
2505
+ VERIFY_ARE_EQUAL(LxsstuLaunchWsl(L"test ! -e /run/tmpfiles.d/x11.conf"), 0L);
2506
2507
// Validate that WSLg-related environment variables are not present.
2508
//