WSL: WSL2 cannot start VS Code

Windows Version

Microsoft Windows [Version 10.0.19045.3208]

WSL Version

1.2.5.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.90.1-microsoft-standard-WSL2

Distro Version

Ubuntu-22.04

Other Software

VS code Version: 1.81.0 (system setup) Commit: 6445d93c81ebe42c4cbd7a60712e0b17d9463e97 Date: 2023-08-02T12:37:13.485Z Electron: 22.3.18 ElectronBuildId: 22689846 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Windows_NT x64 10.0.19045

Repro Steps

If I tried to open both a file or folder by vs code:

code . or code file.txt

I got the following error:

/mnt/c/Program Files/Microsoft VS Code/bin/code: 61: /mnt/c/Program Files/Microsoft VS Code/Code.exe: Exec format error

Expected Behavior

be able to open a file or folder without errors.

Actual Behavior

I got this error:

/mnt/c/Program Files/Microsoft VS Code/bin/code: 61: /mnt/c/Program Files/Microsoft VS Code/Code.exe: Exec format error

Diagnostic Logs

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 13
  • Comments: 21 (1 by maintainers)

Most upvoted comments

In my case following this:

But you must be right, I managed to exec Windows executables when KB5028244 was installed by following this solution : https://stackoverflow.com/a/76826327/822837

Resolved the issue.

The solution for my problem was opened /etc/wsl.conf and change the line systemd=true to #systemd=true

I hope this help you!

@elsaco I couldn’t check, I removed the KB5028244 Windows Update and had to turn on again WSL & VM Machine as mentionned on https://superuser.com/a/1736464/256461 Everything is working now. I suspended Windows Updates for now as an annoying workaround

But you must be right, I managed to exec Windows executables when KB5028244 was installed by following this solution : https://stackoverflow.com/a/76826327/822837

this has resolved the issue on my wsl: https://github.com/microsoft/WSL/issues/8952#issuecomment-1572193568

fyi, this is the error I was getting as well: /mnt/c/Program Files/Microsoft VS Code/bin/code: 61: /mnt/c/Program Files/Microsoft VS Code/Code.exe: Exec format error

@elsaco I couldn’t check, I removed the KB5028244 Windows Update and had to turn on again WSL & VM Machine as mentionned on https://superuser.com/a/1736464/256461 Everything is working now. I suspended Windows Updates for now as an annoying workaround

But you must be right, I managed to exec Windows executables when KB5028244 was installed by following this solution : https://stackoverflow.com/a/76826327/822837

This also worked for me, I also wasn’t able to run explorer.exe, but that comment fix it too.

Following this https://github.com/microsoft/WSL/issues/8952#issuecomment-1568212651

resolved the below for me /mnt/c/Program Files/Microsoft VS Code/bin/code: 61: /mnt/c/Program Files/Microsoft VS Code/Code.exe: Exec format error

@renanlido thanks but then you disable systemd which I require in my setup

I have a similar situation. The root cause seems to have been either a Windows Update or Ubuntu update (not sure which).

My recent Ubuntu updates. The last one before the afore mentioned was:

Start-Date: 2023-07-31  09:17:10
Commandline: apt upgrade
Requested-By: mdr (1574)
Upgrade: yaru-theme-icon:amd64 (22.04.4, 22.04.5), gnome-control-center-faces:amd64 (1:41.7-0ubuntu0.22.04.6, 1:41.7-0ubuntu0.22.04.7), libldap-common:amd64 (2.5.14+dfsg-0ubuntu0.22.04.2, 2.5.15+dfsg-0ubuntu0.22.04.1), ldap-utils:amd64 (2.5.14+dfsg-0ubuntu0.22.04.2, 2.5.15+dfsg-0ubuntu0.22.04.1), libmysqlclient21:amd64 (8.0.33-0ubuntu0.22.04.2, 8.0.33-0ubuntu0.22.04.4), libldap-2.5-0:amd64 (2.5.14+dfsg-0ubuntu0.22.04.2, 2.5.15+dfsg-0ubuntu0.22.04.1), firefox:amd64 (116.0+build1-0ubuntu0.22.04.1~mt2, 116.0+build2-0ubuntu0.22.04.1~mt1), yaru-theme-sound:amd64 (22.04.4, 22.04.5), yaru-theme-gtk:amd64 (22.04.4, 22.04.5), gnome-control-center-data:amd64 (1:41.7-0ubuntu0.22.04.6, 1:41.7-0ubuntu0.22.04.7), gnome-control-center:amd64 (1:41.7-0ubuntu0.22.04.6, 1:41.7-0ubuntu0.22.04.7), yaru-theme-gnome-shell:amd64 (22.04.4, 22.04.5)
End-Date: 2023-07-31  09:17:23

Which I can ensure is not the cause as I have rebooted the host system between 2023-07-31 09:17:23 and 2023-08-03 09:44:37.

However, I suspect it might have to do with KB5028244:

image

I have a similar situation. The root cause seems to have been either a Windows Update or Ubuntu update (not sure which).

However, the capability to run windows executables without running them explicitly through /init, has vanished today.

In the startup debug log I can see the following entry:

proc-sys-fs-binfmt_misc.automount: Path /proc/sys/fs/binfmt_misc is already a mount point, refusing start.
[FAILED] Failed to set up automount Arbitrar…rmats File System Automount Point.
See 'systemctl status proc-sys-fs-binfmt_misc.automount' for details.

However, systemctl status proc-sys-fs-binfmt_misc.automount does not return anything in particular:

$ systemctl status proc-sys-fs-binfmt_misc.automount
○ proc-sys-fs-binfmt_misc.automount - Arbitrary Executable File Formats File System Automount Point
     Loaded: loaded (/lib/systemd/system/proc-sys-fs-binfmt_misc.automount; static)
     Active: inactive (dead)
   Triggers: ● proc-sys-fs-binfmt_misc.mount
      Where: /proc/sys/fs/binfmt_misc
       Docs: https://www.kernel.org/doc/html/latest/admin-guide/binfmt-misc.html
             https://www.freedesktop.org/wiki/Software/systemd/APIFileSystems

Shortly before the above mentioned error during boot, there are a few more errors:

Welcome to Ubuntu 22.04.2 LTS!

Couldn't move remaining userspace processes, ignoring: Input/output error
[   25.308929] Failed to connect to bus: No such file or directory
[   25.513394] scsi 0:0:0:2: Direct-Access     NVMe     KXG50PNV2T04 NVM 4104 PQ: 0 ANSI: 6
[   25.530352] sd 0:0:0:2: Attached scsi generic sg2 type 0
[   25.531478] sd 0:0:0:2: [sdc] 4000797360 512-byte logical blocks: (2.05 TB/1.86 TiB)
[   25.532809] sd 0:0:0:2: [sdc] Write Protect is off
[   25.533439] sd 0:0:0:2: [sdc] Mode Sense: 0f 00 00 00
[   25.535467] sd 0:0:0:2: [sdc] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[   25.545744]  sdc: sdc1 sdc2 sdc3 sdc4 sdc5
[   25.549952] sd 0:0:0:2: [sdc] Attached SCSI disk
[   25.562617] Failed to connect to bus: No such file or directory
[   25.815706] Failed to connect to bus: No such file or directory
[   26.069414] Failed to connect to bus: No such file or directory
[   26.323978] Failed to connect to bus: No such file or directory
Queued start job for default target Graphical Interface.
-.slice: Failed to migrate controller cgroups from /, ignoring: Input/output error

Also, /proc/sys/fs/binfmt_misc/WSLInterop does not exist!

$ ls -la /proc/sys/fs/binfmt_misc/
total 0
drwxr-xr-x 2 root root 0 Aug  4 14:28 .
dr-xr-xr-x 1 root root 0 Aug  4 14:28 ..
-rw-r--r-- 1 root root 0 Aug  4 14:29 python3.10
--w------- 1 root root 0 Aug  4 14:28 register
-rw-r--r-- 1 root root 0 Aug  4 14:28 status

The setting can be set with

$ sudo su -
# echo ":WSLInterop:M::MZ::/init:" > /proc/sys/fs/binfmt_misc/register

which makes the file appear:

 $ ls -la /proc/sys/fs/binfmt_misc/
total 0
drwxr-xr-x 2 root root 0 Aug  4 14:28 .
dr-xr-xr-x 1 root root 0 Aug  4 14:28 ..
-rw-r--r-- 1 root root 0 Aug  4 17:47 WSLInterop
-rw-r--r-- 1 root root 0 Aug  4 14:29 python3.10
--w------- 1 root root 0 Aug  4 17:47 register
-rw-r--r-- 1 root root 0 Aug  4 14:28 status

$ cat /proc/sys/fs/binfmt_misc/WSLInterop
enabled
interpreter /init
flags:
offset 0
magic 4d5a

And CMD.EXE can now be run:

$ /mnt/c/Windows/System32/cmd.exe /c ver
'\\wsl.localhost\Ubuntu\home\mdr\projects\humhub\htdocs'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported.  Defaulting to Windows directory.

Microsoft Windows [Version 10.0.19045.3271]

However, this seems to fix only part of the issue. But may be helping in getting to the source of the problem.

Btw, #10359 seems to be the same issue.