You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
binfmt config cleared on all distro when distro with systemd is terminated #13885
If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'. Otherwise, please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.
How to collect WSL logs
Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:
If you choose to email these logs instead of attaching them to the bug, please send them to [email protected] with the GitHub issue number in the subject, and include a link to your GitHub issue comment in the message body, and reply with '/emailed-logs'.
Regarding to #8843 (comment) it should be fixed now. But it is clearly not or at least not always. Because what i noticed on my Ubuntu 22.04 is that the systemd-binfmt.service has an additional wsl.conf which prevent it to actually run and so the fix from #8843 seems to not have the desired effect.
systemd-binfmt.service - Set Up Additional Binary Formats
Loaded: loaded (/lib/systemd/system/systemd-binfmt.service; static)
Drop-In: /run/systemd/generator/systemd-binfmt.service.d
└─override.conf
/usr/lib/systemd/system/systemd-binfmt.service.d
└─wsl.conf
Active: inactive (dead)
Condition: start condition failed at Thu 2026-02-12 10:52:37 CET; 3min 10s ago
└─ ConditionVirtualization=!wsl was not met
S, it seems that ExecStop=/lib/systemd/systemd-binfmt --unregister is still executed on stop. At least I can reproduce it by running sudo systemctl stop systemd-binfmt.service or by terminating the WSL Distor with wsl.exe -t. Afterward /proc/sys/fs/binfmt_misc/ is basically empty (also in all other still running Distros).
On Ubuntu 24.04 I cannot reproduce it but there is only the override.conf from the fix and not the wsl.conf.
systemd-binfmt.service - Set Up Additional Binary Formats
Loaded: loaded (/usr/lib/systemd/system/systemd-binfmt.service; static)
Drop-In: /run/systemd/generator/systemd-binfmt.service.d
└─override.conf
Furthermore, at least in my case, the WSL integration of Docker Desktop seems also to have some influence. At least it also modifies the entries of /proc/sys/fs/binfmt_misc/.
Before Docker start:
drwxr-xr-x 2 root root 0 Feb 12 11:04 ./
dr-xr-xr-x 1 root root 0 Feb 12 11:10 ../
-rw-r--r-- 1 root root 0 Feb 12 11:10 WSLInterop
-rw-r--r-- 1 root root 0 Feb 12 11:10 python3.10
--w------- 1 root root 0 Feb 12 11:10 register
-rw-r--r-- 1 root root 0 Feb 11 20:05 status
After Docker started:
drwxr-xr-x 2 root root 0 Feb 12 11:04 ./
dr-xr-xr-x 1 root root 0 Feb 12 11:10 ../
-rw-r--r-- 1 root root 0 Feb 12 11:10 WSLInterop
-rw-r--r-- 1 root root 0 Feb 12 11:12 aarch64
-rw-r--r-- 1 root root 0 Feb 12 11:12 arm
-rw-r--r-- 1 root root 0 Feb 12 11:12 mips64
-rw-r--r-- 1 root root 0 Feb 12 11:12 mips64le
-rw-r--r-- 1 root root 0 Feb 12 11:12 ppc64le
-rw-r--r-- 1 root root 0 Feb 12 11:10 python3.10
--w------- 1 root root 0 Feb 12 11:12 register
-rw-r--r-- 1 root root 0 Feb 12 11:12 riscv64
-rw-r--r-- 1 root root 0 Feb 12 11:12 s390x
-rw-r--r-- 1 root root 0 Feb 11 20:05 status
And when stopped again is goes back to the list of before and sometimes WSLInterops is also to gone (but not always). But I did not find out what (in Docker Desktop) is exactly responsible for that.
is creating an override /run/systemd/generator/systemd-binfmt.service.d/override.conf
# Note: This file is generated by WSL to prevent binfmt.d from overriding WSL's binfmt interpreter.
# To disable this unit, add the following to /etc/wsl.conf:
# [boot]
# protectBinfmt=false
[Service]
ExecStop=
ExecStart=/bin/sh -c '(echo -1 > /proc/sys/fs/binfmt_misc/WSLInterop) ; (echo ":WSLInterop:M::MZ::/init:P" > /proc/sys/fs/binfmt_misc/register)'
Which serves to break systemd-binfmt.service, reventing the real service from starting and replacing it with a one-time shell script that registers WSLInterop (and only WSLInterop).
What they should be doing is writing /run/binfmt.d/WSLInterop.conf
:WSLInterop:M::MZ::/init:P
and then just letting systemd-binfmt.conf register that, along with any other requested interpreters.
Confirming on WSL 2.6.3.0 / kernel 6.6.87.2 / Windows 10.0.26200.8037 / Ubuntu 24.04.4 LTS.
Building on Jonas Feller (@J0F3)'s ExecStop analysis and Kevin Puetz (@puetzk) s protectBinfmt override analysis — the override successfully prevents systemd-binfmt --unregister, but the handlers still disappear because systemd's late shutdown unmounts the binfmt_misc filesystem itself.
Evidence
Shutdown monitor service (Before=shutdown.target) planted inside the test distro captured state during shutdown:
binfmt status: enabled
WSLInterop: enabled, interpreter /init, flags: P
mount: binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,relatime)
Handler present when services stop. After wsl --terminate completes, from the host distro:
binfmt_misc still mounted, but all handlers gone — WSLInterop, python3.12, everything. The handlers are cleared during systemd-shutdown's final unmount phase, which protectBinfmt can't prevent because it only overrides systemd-binfmt.service.
State progression (from host, observed via snapshots)
baseline (after wsl --shutdown): WSLInterop flags: PF
after test distro boot: WSLInterop flags: P, python3.12 added
after wsl --terminate: (all handlers gone)
The protectBinfmt override's ExecStart changes flags from PF to P on boot (deletes handler, re-registers with :P). This part works. The problem is the terminate.
Confirmed mitigation
Setting [boot] systemd=false in the distro's wsl.conf prevents the handler loss on terminate.
Note on the manual workaround
echo :WSLInterop:M::MZ::/init:PF > register uses :PF flags but the override expects :P. Next systemd boot's ExecStart fails with Permission denied on re-register. wsl --shutdown is the only safe recovery.
Agree with Kevin Puetz (@puetzk) that writing /run/binfmt.d/WSLInterop.conf and letting systemd-binfmt handle it properly would be cleaner, but the filesystem unmount during late shutdown still needs addressing — via mount propagation, a mount unit override, or binfmt_misc namespace support from kernel 6.7(
Gordon Lam (@yeelam-gordon) — I dug into this issue and found your branch workitem/13885-fix-binfmt-config-cleared-on-termination already has solid fixes for the multi-distro / F-flag-loss / stale-config scenarios. It would be great to get a PR opened from it.
After reviewing the branch I had a few small suggestions (happy to drop them as review comments once a PR is open):
Race tolerance in ExecStartPost — if another distro registers WSLInterop concurrently, the echo -1 > .../WSLInterop or echo ... > .../register can fail and mark systemd-binfmt.service as failed. Suggest swallowing those errors (2>/dev/null || true) and instead verifying the result with a grep on the live entry, e.g.:
Drop the unused [Mount] Options= block in the proc-sys-fs-binfmt_misc.mount.d override — the unmount-prevention comes from DefaultDependencies=no + Before=umount.target, the Options field isn't doing anything.
BinfmtSurvivesDistroTermination test:
VERIFY_ARE_EQUAL the return code of the second distro's wsl.conf write so a setup failure isn't silently swallowed.
Wait for systemd to actually reach running/degraded in both distros before terminating, otherwise the shutdown path isn't really being exercised.
Assert the live kernel entry retains the F flag (grep ^flags:.*F /proc/sys/fs/binfmt_misc/WSLInterop), not just that it's enabled — losing F is the core symptom for Docker / chroot interop and is what regressions would look like.
Repro I was originally chasing: customer hits exec format error running Windows binaries from a WSL2 distro that has other distros also using systemd. Your fix covers it.
Closed my draft (#40610) since it was just your branch + the above polish — better to land it from your branch with the credit.
This should be fixed by #40621 (merged in WSL 2.7.6+). The init now protects binfmt_misc registrations from being wiped when another distro with systemd is terminated. Please update to the latest WSL and let us know if the issue persists.
Activity
github-actions commentedon Dec 12, 2025
Logs are required for review from WSL team
If this a feature request, please reply with '/feature'. If this is a question, reply with '/question'.
Otherwise, please attach logs by following the instructions below, your issue will not be reviewed unless they are added. These logs will help us understand what is going on in your machine.
How to collect WSL logs
Download and execute collect-wsl-logs.ps1 in an administrative powershell prompt:
The script will output the path of the log file once done.
If this is a networking issue, please use collect-networking-logs.ps1, following the instructions in Collect WSL logs for networking issues
Once completed please upload the output files to this GitHub issue.
See Collect WSL logs (recommended method).
If you choose to email these logs instead of attaching them to the bug, please send them to [email protected] with the GitHub issue number in the subject, and include a link to your GitHub issue comment in the message body, and reply with '/emailed-logs'.
MiKom commentedon Dec 12, 2025
/emailed-logs
github-actions commentedon Dec 12, 2025
Diagnostic information
MiKom commentedon Dec 28, 2025
Pinging to make sure the bot doesn't close it. Issue still persists
MiKom commentedon Jan 2, 2026
Pinging again to fend off the bot
J0F3 commentedon Feb 11, 2026
I have the same issue multiple times per day, and it is very annoying.
philippe-granet commentedon Feb 11, 2026
The only reliable workaround I’ve found so far is this one: #8843 (comment)
J0F3 commentedon Feb 12, 2026
Ah, that's a good hint. Thank you Philippe GRANET (@philippe-granet)
Regarding to #8843 (comment) it should be fixed now. But it is clearly not or at least not always. Because what i noticed on my Ubuntu 22.04 is that the systemd-binfmt.service has an additional wsl.conf which prevent it to actually run and so the fix from #8843 seems to not have the desired effect.
S, it seems that
ExecStop=/lib/systemd/systemd-binfmt --unregisteris still executed on stop. At least I can reproduce it by runningsudo systemctl stop systemd-binfmt.serviceor by terminating the WSL Distor withwsl.exe -t. Afterward/proc/sys/fs/binfmt_misc/is basically empty (also in all other still running Distros).On Ubuntu 24.04 I cannot reproduce it but there is only the
override.conffrom the fix and not thewsl.conf.Furthermore, at least in my case, the WSL integration of Docker Desktop seems also to have some influence. At least it also modifies the entries of
/proc/sys/fs/binfmt_misc/.Before Docker start:
After Docker started:
And when stopped again is goes back to the list of before and sometimes
WSLInteropsis also to gone (but not always). But I did not find out what (in Docker Desktop) is exactly responsible for that.puetzk commentedon Mar 9, 2026
They replaced #8843 (comment) with yet another workaround that is fighting with systemd rather than working with it:
Now,
WSL/src/linux/init/init.cpp
Lines 369 to 396 in 218b71b
Which serves to break systemd-binfmt.service, reventing the real service from starting and replacing it with a one-time shell script that registers WSLInterop (and only WSLInterop).
What they should be doing is writing /run/binfmt.d/WSLInterop.conf
and then just letting systemd-binfmt.conf register that, along with any other requested interpreters.
Tycorc commentedon Mar 12, 2026
Confirming on WSL 2.6.3.0 / kernel 6.6.87.2 / Windows 10.0.26200.8037 / Ubuntu 24.04.4 LTS.
Building on Jonas Feller (@J0F3)'s
ExecStopanalysis and Kevin Puetz (@puetzk) sprotectBinfmtoverride analysis — the override successfully preventssystemd-binfmt --unregister, but the handlers still disappear because systemd's late shutdown unmounts the binfmt_misc filesystem itself.Evidence
Shutdown monitor service (
Before=shutdown.target) planted inside the test distro captured state during shutdown:Handler present when services stop. After
wsl --terminatecompletes, from the host distro:binfmt_misc still mounted, but all handlers gone — WSLInterop, python3.12, everything. The handlers are cleared during
systemd-shutdown's final unmount phase, whichprotectBinfmtcan't prevent because it only overridessystemd-binfmt.service.State progression (from host, observed via snapshots)
The
protectBinfmtoverride's ExecStart changes flags from PF to P on boot (deletes handler, re-registers with:P). This part works. The problem is the terminate.Confirmed mitigation
Setting
[boot] systemd=falsein the distro's wsl.conf prevents the handler loss on terminate.Note on the manual workaround
echo :WSLInterop:M::MZ::/init:PF > registeruses:PFflags but the override expects:P. Next systemd boot's ExecStart fails withPermission deniedon re-register.wsl --shutdownis the only safe recovery.Agree with Kevin Puetz (@puetzk) that writing
/run/binfmt.d/WSLInterop.confand lettingsystemd-binfmthandle it properly would be cleaner, but the filesystem unmount during late shutdown still needs addressing — via mount propagation, a mount unit override, or binfmt_misc namespace support from kernel 6.7(fix(init): prevent binfmt_misc handler loss on distro termination
benhillis commentedon May 20, 2026
Gordon Lam (@yeelam-gordon) — I dug into this issue and found your branch
workitem/13885-fix-binfmt-config-cleared-on-terminationalready has solid fixes for the multi-distro /F-flag-loss / stale-config scenarios. It would be great to get a PR opened from it.After reviewing the branch I had a few small suggestions (happy to drop them as review comments once a PR is open):
Race tolerance in
ExecStartPost— if another distro registersWSLInteropconcurrently, theecho -1 > .../WSLInteroporecho ... > .../registercan fail and marksystemd-binfmt.serviceas failed. Suggest swallowing those errors (2>/dev/null || true) and instead verifying the result with a grep on the live entry, e.g.:Drop the unused
[Mount] Options=block in theproc-sys-fs-binfmt_misc.mount.doverride — the unmount-prevention comes fromDefaultDependencies=no+Before=umount.target, the Options field isn't doing anything.BinfmtSurvivesDistroTerminationtest:VERIFY_ARE_EQUALthe return code of the second distro'swsl.confwrite so a setup failure isn't silently swallowed.running/degradedin both distros before terminating, otherwise the shutdown path isn't really being exercised.Fflag (grep ^flags:.*F /proc/sys/fs/binfmt_misc/WSLInterop), not just that it'senabled— losingFis the core symptom for Docker / chroot interop and is what regressions would look like.Repro I was originally chasing: customer hits
exec format errorrunning Windows binaries from a WSL2 distro that has other distros also using systemd. Your fix covers it.Closed my draft (#40610) since it was just your branch + the above polish — better to land it from your branch with the credit.
Prevent binfmt_misc unmount propagation across distros
benhillis commentedon Jun 5, 2026
This should be fixed by #40621 (merged in WSL 2.7.6+). The init now protects binfmt_misc registrations from being wiped when another distro with systemd is terminated. Please update to the latest WSL and let us know if the issue persists.
Let systemd-binfmt register WSLInterop
fix(wsl): stop booting stopped distros from background work
fix(wsl): stop booting stopped distros from background work
fix(wsl): stop booting stopped distros for background work (#27684)