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
[WSL2][systemd][interop] Unable to Execute Windows Binary when systemd enabled #8843
Linux version 5.15.62.1-microsoft-standard-WSL2 (oe-user@oe-host) (x86_64-msft-linux-gcc (GCC) 9.3.0, GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP Wed Aug 24 22:24:20 UTC 2022
$cat /proc/sys/fs/binfmt_misc/WSLInterop
cat: /proc/sys/fs/binfmt_misc/WSLInterop: No such file or directory
Reacted by Katherine Reynolds, Jayjay Montalbo, Marcel Hellwig, Patrick Wu, Zach Rosenberger, Kevin Wu, Ryan Thomas Lynch, jice73, pnck, Neno Ganchev and 42 more
Reacted by pnck, Robert U, unlsycn and Pete Garafano
Reacted by pnck, Pete Garafano and Borja Sánchez García
The interoperability of WSL and Windows relies on WSL init. After systemd is turned on, WSL init will also run under systemd, which may be one of the reasons for breaking the interoperability function.
I don't think it is by design WitherZuo (@WitherZuo). I have both systemd and interop working temporarily in Ubuntu but it stops working when I start another WSL distro.
Once I shutdown WSL and start Ubuntu on its own it works again.
Systemd does that, as those of us who've futzed with alternative systemd solutions in the past have come to know. The solution-slash-workaround is to put this file:
Reacted by Xavier Hsinyuan, Katherine Reynolds, Jayjay Montalbo, Ondrej Balaz, ndrsg, douglarek, ZYA, Thomas Emter, Jan Fooken, Ayon Tarafdar and 13 more
Reacted by ndrsg, Nick, Jan Fooken, Ryan Thomas Lynch and Ogaday
I compared the distro that worked out of the box and the distro that didn't and the difference was existing config files in "/usr/lib/binfmt.d"
Stock Ubuntu out of the box with nothing in "/usr/lib/binfmt.d" works fine
Kali Linux with plenty of packages installed and thus several config files in "/usr/lib/binfmt.d" does not work
Ubuntu on its own works fine.
Kali doesn't work and also breaks Ubuntu.
Deleting everything under "/usr/lib/binfmt.d" in the Kali distro fixes Kali (and stops breaking Ubuntu).
Adding your file to "/usr/lib/binfmt.d" alongside the existing files fixes Kali (and stops breaking Ubuntu).
Re4son Kernel (@Re4son) - thanks for the additional detail. This boils down to Linux not supporting namespacing of binfmt_misc interpreters. Any fix we make is going to be problematic until that is resolved.
It looks like we need to handle the case where the distro has binfmt interpreters installed by adding our own .conf file though.
Systemd does that, as those of us who've futzed with alternative systemd solutions in the past have come to know. The solution-slash-workaround is to put this file:
Also I removed mono.conf from the same directory as they might create a conflicting mapping. After running sudo systemctl restart systemd-binfmt, my executables are working now.
I've tried several binfmt entries but most of the entries I found online did not include the 'PF' flags and resulted in an error.
Reacted by Dominik Stiller, Zed, cjahv, Ayon Tarafdar, Kevin Wu, jice73, pnck, Roman Verenich, Volker Gropp, mhorst00 and 81 more
Reacted by Alexandre Paixao, Kevin, vincent163, Ra-el Peters, Jacob Page, Ed43, DQ, Jan Procházka, Yung Shen, Murilo Komirchuk and 18 more
Reacted by Kirill, Kevin Aleman, Eduardo Marques, Lee Williams and Viktor Suprun
Also I removed mono.conf from the same directory as they might create a conflicting mapping. After running sudo systemctl restart systemd-binfmt, my executables are working now.
I've tried several binfmt entries but most of the entries I found online did not include the 'PF' flags and resulted in an error.
I tried using this solution (for Kali) and while the window launches it is black. Is there anything else that needs to be done?
For me the binfmt went missing every docker run for some reason. I do not know the reason but the fix is obvious - either restart binfmt service or register the format using sudo echo ":WSLInterop:M::MZ::/init:PF" > /proc/sys/fs/binfmt_misc/register
I got tired of manually adding this pre-docker so I fight fire with fire and I made systemd service and path monitor that will do the same if WSLinterop file are missing. Seems to work so far, sharing so maybe some of you will benefit:
Reacted by Felipe Santos, Rui Marques, Joseph Larionov, David Svenson, Nick, bmweller, Robert Pendell, David Kronhardt, Yuichiro Smith, Odd Karsten and 4 more
It seems that Microsoft has now implemented a fix for this? at least on my machine (Windows 11 22H2, WSL version: 2.0.9.0) they now made a unit /run/systemd/generator.early/wsl-binfmt.service
# Note: This file is generated by WSL to prevent binfmt.d from overriding WSL's binfmt interpretor.
# To disable this unit, add the following to /etc/wsl.conf:
# [boot]
# protectBinfmt=false
[Unit]
Description=WSL binfmt restore
After=systemd-binfmt.service
[Service]
Type=oneshot
ExecStart=/bin/sh -c '(echo -1 > /proc/sys/fs/binfmt_misc/WSLInterop-late) ; (echo :WSLInterop-late:M::MZ::/init:P > /proc/sys/fs/binfmt_misc/register)'
This is still not the "correct" solution Lennart Poettering (@poettering) suggested in systemd/systemd#28126 (using /run/binfmt.d, so that the normal systemd-binfmt.service would know about their registration), but it should at least add their service back after both run (and it schedules itself to run immediately afterward).
Thanks for this. It fixed my problem. I will come back later and read the rest of the solutions since this one is quite old and there may be a newer way to handle this issue now. Cheers!
I'm getting a very similar error, but for Linux commands instead. At the very beginning of a new terminal I get:
-bash: /usr/bin/grep: cannot execute binary file: Exec format error
And I also get this:
$ groups
-bash: /usr/bin/groups: cannot execute binary file: Exec format error
However, some other commands that can be found under /usr/bin/, like find and which, work fine for me. I've tried all of the suggestions above and they didn't help. And that isn't a surprise since I didn't actually have any issues running Windows executables, but this error message is the exact same, so I'm wondering if my issue is related.
For background info, this is a fresh WSL2 installation on Windows 10, and after installing WSL2 I installed Docker for Windows, while also setting autoMemoryReclaim to dropcache as suggested here.
Since the other thread ( #8952 ) was closed: I've just had this error with the git credential manager and simply restarting WSL (wsl --shutdown) solved the issue, so I'm not sure if systemd is at fault.
This happens to me sometimes with Ubuntu 24.04, but not always. I currently do not know what the difference between the WSL2 installations of the Ubuntu VMs where. I did the exact same thing, sometimes wslvar worked, sometimes not. 🤷♂️
systemd/systemd#28126 is now closed. The systemd team regard this as an incorrect configuration by WSL, and suggest putting configuration in /run/binfmt.d before calling systemd as a fix.
My current setup (WSL 2.3.24.0, Windows 11 23H2 22631.4391) has the fix in /run/systemd/generator.earlywsl-binfmt.service and it seems to work for me, despite being less elegant than fixing it in /run/binfmt.d.
I'm also still affected by this issue, and it seems like some tools I have (namely ForkGit) seem to work for a while then fail again after an amount of time.
Activity
WitherZuo commentedon Sep 22, 2022
The interoperability of WSL and Windows relies on WSL init. After systemd is turned on, WSL init will also run under systemd, which may be one of the reasons for breaking the interoperability function.
Re4son commentedon Sep 22, 2022
I don't think it is by design WitherZuo (@WitherZuo). I have both systemd and interop working temporarily in Ubuntu but it stops working when I start another WSL distro.
Once I shutdown WSL and start Ubuntu on its own it works again.
reynoldskr commentedon Sep 22, 2022
The
binfmt_mischandler for WSL2 to run Windows binaries either is getting overwritten bysystemdor is never set:systemdenabledsystemddisabledcerebrate commentedon Sep 22, 2022
Systemd does that, as those of us who've futzed with alternative systemd solutions in the past have come to know. The solution-slash-workaround is to put this file:
https://github.com/arkane-systems/bottle-imp/blob/master/othersrc/usr-lib/binfmt.d/WSLInterop.conf
in your /usr/lib/binfmt.d .
Re4son commentedon Sep 22, 2022
Good pointer Alistair Young (@cerebrate), thanks heaps! That helped.
I compared the distro that worked out of the box and the distro that didn't and the difference was existing config files in "/usr/lib/binfmt.d"
Ubuntu on its own works fine.
Kali doesn't work and also breaks Ubuntu.
Deleting everything under "/usr/lib/binfmt.d" in the Kali distro fixes Kali (and stops breaking Ubuntu).
Adding your file to "/usr/lib/binfmt.d" alongside the existing files fixes Kali (and stops breaking Ubuntu).
Thanks for that Alistair Young (@cerebrate), much appreciate it.
benhillis commentedon Sep 23, 2022
Re4son Kernel (@Re4son) - thanks for the additional detail. This boils down to Linux not supporting namespacing of binfmt_misc interpreters. Any fix we make is going to be problematic until that is resolved.
It looks like we need to handle the case where the distro has binfmt interpreters installed by adding our own .conf file though.
dbbao commentedon Sep 26, 2022
有什么解决方案吗,我也碰到这个问题了
PhyX-Meow commentedon Sep 26, 2022
@lhrbest 这里已经给了 workaround 了
dbbao commentedon Sep 26, 2022
我是Ubuntu 20.04,会报如下的错误:
``root@lhrxxt:/mnt/f/pwsh# cmd.exe
<3>WSL (996) ERROR: UtilConnectUnix:511: connect failed 2
root@lhrxxt:/mnt/f/pwsh#
root@lhrxxt:/mnt/f/pwsh# ll /usr/lib/binfmt.d/
total 12
drwxr-xr-x 2 root root 4096 Sep 26 15:30 ./
drwxr-xr-x 122 root root 4096 Sep 14 10:57 ../
-rw-r--r-- 1 root root 27 Sep 26 15:30 WSLInterop.conf
root@lhrxxt:/mnt/f/pwsh# cmd.exe
<3>WSL (1000) ERROR: UtilConnectUnix:511: connect failed 2
root@lhrxxt:/mnt/f/pwsh#
root@lhrxxt:/mnt/f/pwsh#
PhyX-Meow commentedon Sep 26, 2022
@lhrbest Try restart wsl. Normally there should be a file named
WSLInterop.kpko commentedon Dec 5, 2022
Hi,
I'm using https://github.com/yuk7/ArchWSL and enabling systemd reliably broke the ability to execute Windows applications from WSL. I resolved the issue by generating a file in /usr/lib/binfmt.d/WSLInterop.conf with the following content:
Also I removed mono.conf from the same directory as they might create a conflicting mapping. After running
sudo systemctl restart systemd-binfmt, my executables are working now.I've tried several binfmt entries but most of the entries I found online did not include the 'PF' flags and resulted in an error.
romaluca commentedon Dec 21, 2022
Hi, i have the same problem and the file:
https://github.com/arkane-systems/bottle-imp/blob/master/othersrc/usr-lib/binfmt.d/WSLInterop.conf
not exists anymore.
Where i can find it?
Thasnk
PhyX-Meow commentedon Dec 21, 2022
Luca Romagnoli (@romaluca) It is here, https://github.com/arkane-systems/bottle-imp/blob/v0.13.0/othersrc/usr-lib/binfmt.d/WSLInterop.conf
cvernooy23 commentedon Jan 12, 2023
I tried using this solution (for Kali) and while the window launches it is black. Is there anything else that needs to be done?
ststefa commentedon Feb 17, 2023
Thanks a lot, this solved the problem also for me on Debian bullseye. Learned something new today ;)
34 remaining items
alkuzad commentedon Nov 3, 2023
For me the binfmt went missing every docker run for some reason. I do not know the reason but the fix is obvious - either restart binfmt service or register the format using
sudo echo ":WSLInterop:M::MZ::/init:PF" > /proc/sys/fs/binfmt_misc/registerI got tired of manually adding this pre-docker so I fight fire with fire and I made systemd service and path monitor that will do the same if WSLinterop file are missing. Seems to work so far, sharing so maybe some of you will benefit:
/etc/systemd/system/wslinterop-monitor.path
/etc/systemd/system/wslinterop-force.service
Then:
puetzk commentedon Dec 2, 2023
It seems that Microsoft has now implemented a fix for this? at least on my machine (Windows 11 22H2, WSL version: 2.0.9.0) they now made a unit /run/systemd/generator.early/wsl-binfmt.service
This is still not the "correct" solution Lennart Poettering (@poettering) suggested in systemd/systemd#28126 (using /run/binfmt.d, so that the normal systemd-binfmt.service would know about their registration), but it should at least add their service back after both run (and it schedules itself to run immediately afterward).
https://docs.kernel.org/admin-guide/binfmt-misc.html
However, it has another shortcoming - compared to all the settings proposed here, it's missing the
Flags: F(fix binary): https://docs.kernel.org/admin-guide/binfmt-misc.html, which means that this registration doesn't work in a chroot (or other mount namespace that doesn't have wsl's/initmounted).earlofhemsley commentedon Apr 5, 2024
#8843 (comment)
Thanks for this. It fixed my problem. I will come back later and read the rest of the solutions since this one is quite old and there may be a newer way to handle this issue now. Cheers!
syigzaw commentedon Apr 12, 2024
I'm getting a very similar error, but for Linux commands instead. At the very beginning of a new terminal I get:
And I also get this:
However, some other commands that can be found under
/usr/bin/, likefindandwhich, work fine for me. I've tried all of the suggestions above and they didn't help. And that isn't a surprise since I didn't actually have any issues running Windows executables, but this error message is the exact same, so I'm wondering if my issue is related.For background info, this is a fresh WSL2 installation on Windows 10, and after installing WSL2 I installed Docker for Windows, while also setting
autoMemoryReclaimtodropcacheas suggested here.pfeileon commentedon Apr 18, 2024
Since the other thread ( #8952 ) was closed: I've just had this error with the git credential manager and simply restarting WSL (
wsl --shutdown) solved the issue, so I'm not sure ifsystemdis at fault.smartexpert commentedon May 15, 2024
None of the above worked for me. However, on WSL2 running Ubuntu 20.04.04 LTS this worked:
Exit WSL on Powershell via
wsl --shutdownand then restart WSL.The solution was sourced from here: #10363 (comment) credits to Martin Rüegg (@martin-rueegg)
trallnag commentedon Aug 8, 2024
Just ran into this randomly for the first time in a long time. Simple restart of the distributions seems to have fixed it.
oxivanisher commentedon Oct 16, 2024
This happens to me sometimes with Ubuntu 24.04, but not always. I currently do not know what the difference between the WSL2 installations of the Ubuntu VMs where. I did the exact same thing, sometimes
wslvarworked, sometimes not. 🤷♂️michaelmhoffman commentedon Oct 23, 2024
systemd/systemd#28126 is now closed. The systemd team regard this as an incorrect configuration by WSL, and suggest putting configuration in
/run/binfmt.dbefore calling systemd as a fix.My current setup (WSL 2.3.24.0, Windows 11 23H2 22631.4391) has the fix in
/run/systemd/generator.earlywsl-binfmt.serviceand it seems to work for me, despite being less elegant than fixing it in/run/binfmt.d.I suggest that the issue be closed as fixed.
benhillis commentedon Mar 12, 2025
Fixed with https://github.com/microsoft/WSL/releases/tag/2.5.1
🔧 Updated hack from requireWslu.sh to fix WSL interoperability fix
klasfahlberg commentedon Mar 3, 2026
I'm till affected by this issue. Is it the same bug as this one or a new one? For info see
https://youtrack.jetbrains.com/issue/IJPL-236538
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
xenobytezero commentedon Mar 26, 2026
I'm also still affected by this issue, and it seems like some tools I have (namely ForkGit) seem to work for a while then fail again after an amount of time.
hoerup commentedon Jun 30, 2026
#40621
looks like it's getting fixed in wsl 2.9.x https://github.com/microsoft/WSL/releases/tag/2.9.3