When running code . in ubuntu terminal, the output is: run-detectors: unable to find an interpreter for /mnt/c/Users/MyUserName/AppData/Local/Programs/Microsoft VS Code/Code.exe
So i found a fix and tested with Ubuntu-20.04, Ubuntu-22.04, Ubuntu-24.04 from https://github.com/microsoft/WSL/issues/10239
What i did in my ubuntu terminal:
A. Open ubuntu terminal you are using and set the configuration, save and close: sudo nano /etc/wsl.conf
[boot] systemd=false
B. Create a configuration, set, save and close: sudo nano /usr/lib/binfmt.d/WSLInterop.conf
:WSLInterop:M::MZ::/init:PF
C. Open poweshell, shutdown the running ubuntu terminal:
wsl —shutdown
It fixes the first problem, but it produces another issue: sudo systemctl restart mysql [sudo] password for username: System has not been booted with systemd as init system (PID 1). Can't operate. Failed to connect to bus: Host is down
Can somebody help. Thanks
So looks like Microsoft broke more interop stuff again!
So if you want use of systemctl
you need systemd
enabled in the conf
# /etc/wsl.conf
[boot]
systemd=true
This will fix your sudo systemctl restart mysql
and anything else that uses systemd
(after a wsl --shutdown
and restart)
However this gives your original error again where you're unable to access executables on Windows. WSL has an interop handler that is supposed to let this work but something seems to have broken it.
The default interop is :WSLInterop:M::MZ::/init:
but if we replace this with one that has PF
flags appended where
P
= Preserve argv[0] (keeps the original command intact)
F
= Fix binary (handles path translation between WSL and Windows properly)
Then this should get things working again.
You can test by:
Check for the current Interop handler, we expect to see WSLInterop
ls /proc/sys/fs/binfmt_misc/ | grep WSL
If it's there, we can remove it
echo -1 | sudo tee /proc/sys/fs/binfmt_misc/WSLInterop 2>/dev/null || true
Then recreate it with the PF
flags
echo ':WSLInterop:M::MZ::/init:PF' | sudo tee /proc/sys/fs/binfmt_misc/register
From there you should be able to run commands like code .
again.
This won't persist across restarts though, so you can either repeat it till Microsoft figures something out or create a service that will do it for you.
To create a service:
sudo tee /etc/systemd/system/fix-wsl-interop.service << 'EOF'
[Unit]
Description=Fix WSL Interop Handler with PF flags
Documentation=https://github.com/microsoft/WSL/issues/8843
After=multi-user.target proc-sys-fs-binfmt_misc.mount
Requires=proc-sys-fs-binfmt_misc.mount
[Service]
Type=oneshot
ExecStart=/bin/bash -c 'if [ -f /proc/sys/fs/binfmt_misc/WSLInterop ]; then echo -1 > /proc/sys/fs/binfmt_misc/WSLInterop; fi; echo ":WSLInterop:M::MZ::/init:PF" > /proc/sys/fs/binfmt_misc/register'
RemainAfterExit=yes
StandardOutput=journal
StandardError=journal
[Install]
WantedBy=multi-user.target
EOF
Enable it on start:
sudo systemctl enable fix-wsl-interop.service
This affects any tool that needs to translate Linux paths to Windows paths when launched from WSL.
When it comes to removal down the road, you can clean up the service:
# Stop the service
sudo systemctl stop fix-wsl-interop.service
# Disable the service
sudo systemctl disable fix-wsl-interop.service
# Remove the service
sudo rm /etc/systemd/system/fix-wsl-interop.service
# Reload systemd
sudo systemctl daemon-reload
Thanks to kpko for the original solution