What is binfmt_misc?
Linux miscellaneous binary formats
binfmt_misc is a Linux kernel feature that lets you register an interpreter for a kind of program the kernel can't run itself, such as an x86 binary on an ARM computer.
Each registration says how to recognise the program, usually by the first bytes of the file (its "magic"), and which interpreter should run it. They live under /proc/sys/fs/binfmt_misc/: you register one by writing a line to the register file, and each entry then appears as its own file showing whether it's enabled, its interpreter and its flags. When the kernel is asked to execute a file that matches an entry, it starts the interpreter instead and passes it the program. The F flag tells the kernel to open the interpreter at registration time, which is what makes it work inside containers whose filesystems don't contain the interpreter at all.
This is how Docker runs amd64 images on Apple Silicon. Docker Desktop registers Apple's Rosetta, and you can also register QEMU's user-mode emulators (for example with docker run --privileged --rm tonistiigi/binfmt --install amd64). If no interpreter is registered, starting an x86 container fails with exec format error. Registrations live in the kernel's memory, so ones you add by hand disappear when Docker Desktop's VM restarts. binfmt_misc only translates individual programs; running a whole x86 operating system needs a full virtual machine, as with QEMU and TCG. The Apple Silicon lab guide shows the handlers registered on a real Mac.
Lessons that use binfmt_misc
- Building a network lab on an Apple Silicon MacTeaches this term · Beginner · 45 min
Run real network labs on an M-series Mac: native FRR and Linux containers, x86-only images through Rosetta, and full x86 VyOS VMs under QEMU in Docker, with the pitfalls that stop most people and a starter lab that mixes all three.