WSL: WSL2 (Preview) cannot run .exe files: exec format error: wsl.exe
Version
Microsoft Windows [Version 10.0.22621.521]
WSL Version
- WSL 2
- WSL 1
Kernel Version
5.15.62.1-microsoft-standard-WSL2
Distro Version
Ubuntu 22.04
Other Software
systemd 249.11-0ubuntu3.3
WSL version: 0.68.2.0 Kernel version: 5.15.62.1 WSLg version: 1.0.44 MSRDC version: 1.2.3401 Direct3D version: 1.606.4 DXCore version: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows version: 10.0.22621.521
Repro Steps
- [optional] disable wslg
- [optional] enable
systemdsupport - make sure
interopis not disabled - attempt to run
wsl.exe --versionfrom any shell inside WSL2 ls /proc/sys/fs/binfmt_misc/for presence ofWSLInterop
Expected Behavior
wsl.exewill exe will execute and output version on terminal/proc/sys/fs/binfmt_misc/will contain custom binary format for WSL interop
Actual Behavior
After upgrade to preview version of WSL2 (ver. 0.68.2.0 from Github on non-Insider build) it was possible to run Windows binaries from within WSL2 by simply having them in PATH and typing binary.exe with systemd enabled and disabled.
After Windows build 22H2 upgrade this is not longer possible. Shell sees binaries in PATH but its not possible to run them, error message being exec format error: wsl.exe. After further inspection I found WSL interop is not registered with binfmt_misc:
~ $ ls /proc/sys/fs/binfmt_misc/
llvm-15-runtime.binfmt qemu-arm qemu-mips64el qemu-riscv64 register
qemu-aarch64 qemu-mips64 qemu-ppc64le qemu-s390x status
After upgrade I noticed Hypervisor Platform was disabled although I am sure I had it enabled before. I reenabled it but it didn’t solve the issue.
Diagnostic Logs
~ $ cat /etc/wsl.conf
[boot]
systemd = true
[automount]
enabled = true
mountFsTab = true
root = /mnt/
options = "metadata,umask=2,fmask=1,case=off"
[network]
generateHosts = true
generateResolvConf = true
[interop]
enabled = true
~ $ cat /mnt/c/Users/blami/.wslconfig
[wsl2]
guiApplications = false
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 7
- Comments: 28
The issue is that enabling systemd somehow alters
/proc/sys/fs/binfmt_misc/The file (or filelike??) entryWSLInterop.confgoes missing.I’ve re-written the answer here rather than just linking as the original reference thread is getting rather long and has dead links. The oneliner elimiates that problem.
The solution (from here) is to replace that file. Windows executable files start with the two letters
MZThe following tells Linux what to do when trying to run files that start with those letters.I;m using the 23.04 image from links in this post I guess this is a bug in packaging, or during installation, but I’ve no idea who to tell.
@the-moog’s solution worked! The only extra step I had to add was unmasking the systemd-binfmt service in order to get it working. So to add to his steps. I unmask the service, restart it, then re-mask it to return it back to its previous protected state besides the new modification.
just in case if anyone is still facing the issue, try disabling systemd in /etc/wsl.conf in the distro.
Disabling
systemdsupport in/etc/wsl.confresolves the issue.After
wsl.exe --shutdownand relaunch:Is this some sort of
binfmt_miscsetup race condition?Solutions here didnt work for me. For vscode 😭
/mnt/d/Microsoft VS Code/bin/code: 61: /mnt/d/Microsoft VS Code/Code.exe: Exec format errorThe only thing that temporarily fixes the issue for me:
wslrm -rf ~/.vscode-serverwsl --shutdownVS code will work for a short period before the error randomly comes back and I have to repeat my steps.
Anybody else having this issue or know of a permanent fix?
I am getting this error because of minikube. The commands above would fix the problem until I ran minikube again. Are there any other options?
Thanks @tardis89 The command solves the issue, and now
codestarts fromwsl. Can you explain what was the problem, and how do these command solve the issue?That’s exactly what it is. Specifically, it’s #8843 , and I posted a workaround over in that issue.
My only fix was to stop using Docker Desktop and to manually install docker onto WSL. After that, minikube stopped breaking my command line.
Thanks for the solution!
Same problem after upgrade to Ubuntu 23.04.
Shutting down systemd didn’t solve the problem
Win11 22h2 22621.1413 WSL2
upd Same problem was after updating to 22.10. Last time and now the problem was solved by complete reinstall distro… If I didnt have my own env-build project, I’d be just mad. Solve this issue…
Environments
Details
I upgrade to Ubuntu 23.04 today by executing
do-release-upgrade. After upgrade process, I findwslfetchgoes wrong on my device.systemdenabledWhen switching
systemd = falsein/etc/wsl.conf, this issue does solved with some other informations.systemddisabledMy
/etc/wsl.conflooks like follows:For me this helps but it doesn’t solve it, because the problem reappears later and I need to run these commands again!
In my case, I found out my Docker Desktop wasn’t running (:
thanks that worked for me, just had to also restart wsl
Works perfectly! Thank you…
[like] Brian Kroth (GSL) reacted to your message:
Same issue here.
/etc/release
Only works when disabling systemd
@cerebrate Thanks! Not sure why I did not find that one. Will mark mine as duplicate of it. And thanks for workaround. Did some reading and TIL how
binfmtworks!