The problem#

When interoperability with Windows executables in WSL is broken, launching programs like explorer.exe, code, or clip.exe fails. The system reports something like:

text
cannot execute binary file: Exec format error

The cause#

This is caused by a missing registration file in binfmt.d, which tells the Linux kernel how to handle Windows PE binaries.

The fix#

Create /usr/lib/binfmt.d/WSLInterop.conf with the following content:

text
:WSLInterop:M::MZ::/init:PF
sh
sudo mkdir -p /usr/lib/binfmt.d
echo ':WSLInterop:M::MZ::/init:PF' | sudo tee /usr/lib/binfmt.d/WSLInterop.conf
sudo systemctl restart systemd-binfmt

What’s happening under the hood#

The binfmt_misc registration tells the kernel that files with the MZ magic bytes — characteristic of Windows executables — should be handled via /init, with the right flags for preservation and binary fixing.

Why the file disappears#

Distro upgrades, manual cleanup, or a minimal distro install without WSL-specific packages can wipe out this configuration.

Verifying it works#

sh
cat /proc/sys/fs/binfmt_misc/WSLInterop
explorer.exe .