Skip to content

Instantly share code, notes, and snippets.

@ikorchynskyi
Last active April 19, 2024 13:09
Show Gist options
  • Save ikorchynskyi/da0d669af2feb27903f4f3c54d1acbfa to your computer and use it in GitHub Desktop.
Save ikorchynskyi/da0d669af2feb27903f4f3c54d1acbfa to your computer and use it in GitHub Desktop.
WSL2 "Exec format error" issue

The issue is that enabling systemd somehow alters /proc/sys/fs/binfmt_misc/ The file (or filelike??) entry WSLInterop.conf goes 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 MZ The following tells Linux what to do when trying to run files that start with those letters.

sudo sh -c 'echo :WSLInterop:M::MZ::/init:PF > /usr/lib/binfmt.d/WSLInterop.conf'
sudo systemctl restart systemd-binfmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment