Score:1

WSL2 stopped running windows tools seemingly all of a sudden - cannot execute binary file: Exec format error

br flag

I have been using WSL2 for almost a year now and was always able to run windows tools from it without any problems.

Today I have noticed I am unable to do it anymore:

mark@L-R910LPKW:~$ alias npp
alias npp='/mnt/c/Program\ Files/Notepad++/notepad++.exe'
mark@L-R910LPKW:~$ ls -l /mnt/c/Program\ Files/Notepad++/notepad++.exe
-r-xr-xr-x 1 mark mark 6629712 Apr  4 13:58 '/mnt/c/Program Files/Notepad++/notepad++.exe'
mark@L-R910LPKW:~$ npp
-bash: /mnt/c/Program Files/Notepad++/notepad++.exe: cannot execute binary file: Exec format error
mark@L-R910LPKW:~$

And it does not matter which windows tool I am trying to run - it does not run any.

A quick search of the Internet brought me to /proc/sys/fs/binfmt_misc/WSLInterop, but I cannot create it:

mark@L-R910LPKW:~$ sudo -i
-bash: /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe: cannot execute binary file: Exec format error
root@L-R910LPKW:~# id
uid=0(root) gid=0(root) groups=0(root)
root@L-R910LPKW:~# echo 1 > /proc/sys/fs/binfmt_misc/WSLInterop
-bash: /proc/sys/fs/binfmt_misc/WSLInterop: Permission denied
root@L-R910LPKW:~#

I think it is an outdated piece of information anyway, because I can see a status file there and:

root@L-R910LPKW:~# cat /proc/sys/fs/binfmt_misc/status
enabled
root@L-R910LPKW:~#

I think there was some kind of an update to Windows (our work laptops are updated automatically) that broke it.

Finally, my details are:

root@L-R910LPKW:~# uname -a
Linux L-R910LPKW 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
root@L-R910LPKW:~#

enter image description here

Any help is greatly appreciated.

Score:1
ru flag

From what I've read, this is a "known issue" with WSL2 in Windows 11 when you enable systemd ... i.e.

/etc/wsl.conf contains

[boot]
systemd=true

You can either remove that, or:

Check the contents/existence of /usr/lib/binfmt.d/WSLInterop.conf - it probably won't exist - so

Firstly, run this

sudo sh -c 'echo :WSLInterop:M::MZ::/init:PF > /usr/lib/binfmt.d/WSLInterop.conf'

or if you are root

echo :WSLInterop:M::MZ::/init:PF > /usr/lib/binfmt.d/WSLInterop.conf

Then

sudo systemctl restart systemd-binfmt

Tested and works on my systems (didn't realise it stopped working, but then I very rarely use Windows commands in WSL)

If that still doesn't work (reported not to fully work on some systems)

wsl --shutdown

Then go back into WSL and you should be good

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.