Skip to content

Installing Miscellaneous Binary Format (binfmts)

Install binfmts

The binfmt_misc kernel module, contained in versions 2.1.43 and later of the Linux kernel, allows system administrators to register interpreters for various binary formats based on a magic number or their file extension, and cause the appropriate interpreter to be invoked whenever a matching file is executed.

apt install binfmt-support

Install Qemu

The package provides the user mode emulation, built statically. In this mode QEMU can launch Linux processes compiled for one CPU on another CPU.

The qemu-user-static package registers binary formats which the provided emulators can handle, so that it will be possible to run foreign binaries directly.

apt install qemu-user-static

Configure for aarch64 Architecture (arm64)

When not enabled already.

update-binfmts --enable qemu-aarch64

Check the registration which is in the kernel module and not in the binfmts database.

cat /proc/sys/fs/binfmt_misc/qemu-aarch64

Execute ARM 64-bit binary using an environment variable to set the -L option for the underwater executed qemu-aarch64-static.

To make most needed arm libraries available install the package gcc-aarch64-linux-gnu.

QEMU_LD_PREFIX="/usr/aarch64-linux-gnu" hello-world.bin

The shell command above is the same as the next command.

qemu-aarch64-static -L "/usr/aarch64-linux-gnu" hello-world.bin

Configure for Windows x86-64 Architecture (Wine)

Package configuration

Install the package which also is will install dependency package binfmt-support.

apt install wine-binfmt

Manual configuration

Install and enable execution of Windows 64-bit executables.

update-binfmts --install wine /usr/bin/wine --magic MZ --offset 0

This how to remove the previous made registration.

update-binfmts --remove wine /usr/bin/wine

Check the configuration

Check if wine is registered.

update-binfmts --display wine

Executing local compiled binary

Execute the Windows executable adding the paths to find the needed dynamic libraries (DLL's).

WINEPATH='Z:\usr\x86_64-w64-mingw32\lib;Z:\usr\lib\gcc\x86_64-w64-mingw32\13-posix;lib' ./hello-world.exe 

The shell command above is actually calling

WINEPATH='Z:\usr\x86_64-w64-mingw32\lib;Z:\usr\lib\gcc\x86_64-w64-mingw32\13-posix;lib' /usr/bin/wine hello-world.exe

The relative lib is a subdirectory of the directory where hello-world.exe executable is in, to find a DLL.