-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WSL2][systemd][interop] Unable to Execute Windows Binary when systemd enabled #8843
Comments
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. I have both systemd and interop working temporarily in Ubuntu but it stops working when I start another WSL distro. |
The
|
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: in your /usr/lib/binfmt.d . |
Good pointer @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. Thanks for that @cerebrate, much appreciate it. |
@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. |
有什么解决方案吗,我也碰到这个问题了 |
@lhrbest 这里已经给了 workaround 了 |
我是Ubuntu 20.04,会报如下的错误: |
@lhrbest Try restart wsl. Normally there should be a file named |
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: :WSLInterop:M::MZ::/init:PF Also I removed mono.conf from the same directory as they might create a conflicting mapping. After running 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. |
Hi, i have the same problem and the file: |
Thank you so much for posting this! ❤️ I am in the same situation. My executables are now working, though the |
I tried using this solution (for Kali) and while the window launches it is black. Is there anything else that needs to be done? |
Thanks a lot, this solved the problem also for me on Debian bullseye. Learned something new today ;) |
Hello everyone, thanks to your comments, I was able to solve the problem that my Windows executables were not working after the activation of systemd, just by adding the above mentioned entry to the Here is a one-liner for you: sudo sh -c 'echo :WSLInterop:M::MZ::/init:PF > /usr/lib/binfmt.d/WSLInterop.conf' After (tested on WSL2 @ Ubuntu22.04 and Debian bookworm/sid) |
Thanks @freckhard your solution solved it for me, as well! I was using a custom Fedora distro. |
I'm seeing this issue in #9778 however: However, I get wget https://github.com/arkane-systems/bottle-imp/blob/master/othersrc/usr-lib/binfmt.d/WSLInterop.conf Any pointers on the best way to resolve would be appreciated |
Sorry, file moved in the 1.0 release. Try here: |
@freckhard Can confirm this worked for me as well. |
The
In my case what solved was disabling the cli interpreter using the command: |
Following @tianon's instructions worked for me:
I then did This seems like the most sensible workaround as it disables the service that is removing the WSLInterop capabilities. The |
Yes, windows update alone was what solved the issue ... |
This was reported on systemd as systemd/systemd#28126. @poettering says the following there:
Originally posted by @poettering in systemd/systemd#28126 (comment) |
Will |
I ran into the same issue on arch linux after install dotnet, notepad.exe cannot run, uninstall dotnet does not work. Then did google search, found page here, tried the one liner fix: now works perfectly, including vscode. Just want to post and hope this would also help others. |
The suggestion to configure systemd-binfmt via /run/binfmt.d seems like something aligns with things that already generate interop units in /run for Hopefully microsoft sees it the same way... |
Fixed it for me thanks |
Worked for me on Win11 Pro Preview |
Issue is still prevalent, hope this gets resolved soon. I had to disable systemd to link WSL ubuntu (22.04.02) to windows git credentials. |
…mono-runtime is installed and systemd is enabled. Trying to run "explorer.exe" from a WSL/Ubuntu command prompt, for example, would result in the following error: run-detectors: unable to find an interpreter for /mnt/c/Windows/explorer.exe The fix was taken from microsoft/WSL#4567 (comment). (I confirmed that the mono-runtime package added the cli entry that caused the problem by running "update-binfmts --display".) I'd tried the following but they didn't work for me: microsoft/WSL#8843 (comment) (Create /usr/lib/binfmt.d/WSLInterop.conf.) microsoft/WSL#8843 (comment) (sudo systemctl mask systemd-binfmt.service)
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 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: /etc/systemd/system/wslinterop-monitor.path
/etc/systemd/system/wslinterop-force.service
Then:
|
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 @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 |
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:
And I also get this:
However, some other commands that can be found under For background info, this is a fresh WSL2 installation on Windows 10, and after installing WSL2 I installed Docker for Windows, while also setting |
Since the other thread ( #8952 ) was closed: I've just had this error with the git credential manager and simply restarting WSL ( |
None of the above worked for me. However, on WSL2 running Ubuntu 20.04.04 LTS this worked:
Exit WSL on Powershell via The solution was sourced from here: #10363 (comment) credits to @martin-rueegg |
Just ran into this randomly for the first time in a long time. Simple restart of the distributions seems to have fixed it.
|
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 |
systemd/systemd#28126 is now closed. The systemd team regard this as an incorrect configuration by WSL, and suggest putting configuration in My current setup (WSL 2.3.24.0, Windows 11 23H2 22631.4391) has the fix in I suggest that the issue be closed as fixed. |
Version
0.67.6.0
WSL Version
Kernel Version
Distro Version
Ubuntu 22.04
Other Software
No response
Repro Steps
/etc/wsl.conf
, enable systemd support. (https://devblogs.microsoft.com/commandline/systemd-support-is-now-available-in-wsl/)wsl.exe --shutdown
in wsl2 shell, and reopen the shell.wsl.exe --version
or some other PE binaries, and shell will warn you that the "exec format error" or "MZ: not found"Expected Behavior
Able to execute any valid PE binaries.
Actual Behavior
"exec format error" or "MZ: not found"
Diagnostic Logs
The text was updated successfully, but these errors were encountered: