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:
cannot execute binary file: Exec format errorThe 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:
:WSLInterop:M::MZ::/init:PFsudo mkdir -p /usr/lib/binfmt.d
echo ':WSLInterop:M::MZ::/init:PF' | sudo tee /usr/lib/binfmt.d/WSLInterop.conf
sudo systemctl restart systemd-binfmtWhat’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#
cat /proc/sys/fs/binfmt_misc/WSLInterop
explorer.exe .