binfmt_misc (Miscellaneous Binary Format) is a capability of the Linux kernel which allows arbitrary executable file formats to be recognized and passed to certain user space applications, such as emulators and virtual machines. It is one of a number of binary format handlers in the kernel that are involved in preparing a user-space program to run.
The executable formats are registered through the special purpose file system
binfmt_misc file-system interface (usually mounted under part of /proc). This is either done directly by sending special sequences to the
register procfs file or using a wrapper like Debian-based distributions binfmt-support package or systemd's
register file contains lines which define executable types to be handled. Each line is of the form:
nameis the name of the binary format.
- If it is
E, the executable file format is identified by its filename extension:
magicis the file extension to be associated with the binary format;
- If it is
M, the format is identified by
magicnumber at an absolute
0) in the file and
maskis a bitmask (defaults to all
0xFF) indicating which bits in the number are significant.
- If it is
interpreteris a program that is to be run with the matching file as an argument.
flags(optional) is a string of letters, each controlling a certain aspect of
Pto preserve the original program name typed by user in command line — by adding that name to
interpreterhas to be aware of this so it can correctly pass that additional parameter to the interpreted program as its
Oto open the program file and pass its file descriptor to the
interpreterso it could read an otherwise unreadable file (for which the user does not have the "Read" permission).
Cto determine new process credentials based on program file rather than
interpreterfile (see setuid); implies
Fto make the kernel open the binary at configuration time instead of lazily at startup time, so that it is available inside other mount namespaces and chroots as well.
Each format has a corresponding file entry in the
/proc/sys/fs/binfmt_misc directory which can be read to get information about a given file format.
$ echo -1 >/proc/sys/fs/binfmt_misc/status # all entries $ echo -1 >/proc/sys/fs/binfmt_misc/qemu-xtensa # single entry
Another common usage is to execute PE executables (compiled for MS-DOS or Microsoft Windows) through Wine. For example, the following line will run DOS and Windows EXE files (identified by the "MZ" type code) using Wine:
binfmt_misc can be used for Go as a scripting language.
- Kernel Support for miscellaneous Binary Formats (binfmt_misc) The Linux Kernel documentation
- How programs get run, January 28, 2015, by David Drysdale, LWN.net
- Details of package binfmt-support in sid, Debian
- systemd-binfmt.service, freedesktop.org
- binfmt.d, freedesktop.org
- Java(tm) Binary Kernel Support for Linux v1.03 The Linux Kernel documentation
- Mono(tm) Binary Kernel Support for Linux The Linux Kernel documentation
- Guide:Running Mono Applications
- Official QEMU mirror, QEMU
- Using Go as a scripting language in Linux, Cloudflare, 2018-02-20, retrieved 2019-05-05
- Project home page Archived on archive.org