@alswl: Did you know the Linux kernel has a feature introduced in 1997 that allows Apple Silicon Macs to efficiently run x86 containers? It's called binfmt_misc, introduced in Linux 2.1.43, nearly 30 years ago. The principle is extremely simple: Linux...

X AI KOLs Timeline News

Summary

This article introduces the binfmt_misc feature introduced in the Linux kernel in 1997. It allows registering rules to hand off binary execution to a specified interpreter. Today, combined with Rosetta on Apple Silicon Macs, it enables efficient x86 container operation, achieving performance close to 70-90% of native.

Did you know the Linux kernel has a feature introduced in 1997 that allows Apple Silicon Macs to efficiently run x86 containers? It's called binfmt_misc, introduced in Linux 2.1.43, nearly 30 years ago. The principle is extremely simple: When the Linux kernel executes a binary file, it first reads the magic number from the file header. If you have pre-registered a rule in /proc/sys/fs/binfmt_misc/ — "when encountering a file with this magic, hand it to a specific interpreter" — the kernel automatically forwards execution to that interpreter. It's essentially the same as the #!/bin/bash shebang mechanism, except it matches the binary file header. Initially, it was used to allow Linux to directly "run" Java class files and Windows PE executables. Later, QEMU leveraged this mechanism for user-mode cross-architecture emulation — running x86 ELF binaries directly on ARM Linux, with the kernel automatically calling qemu-x86_64 translation. Then Apple came along. On an Apple Silicon Mac, when starting a Linux VM with Colima / Lima (using macOS's Virtualization.framework) and enabling rosetta: true, the following happens: 1. macOS mounts the Rosetta translator binary into the Linux VM's /mnt/lima-rosetta/rosetta via virtio-fs 2. Inside the VM, a standard binfmt_misc rule is registered: when encountering the x86_64 ELF magic (7f454c46...02003e00), hand it to /mnt/lima-rosetta/rosetta 3. From then on, any x86_64 binary executed in the VM is automatically forwarded by the kernel to Rosetta for translation This is completely transparent to containers — `docker run --platform linux/amd64 nginx`, Docker pulls the x86 image, container processes are x86 ELF, and the Linux kernel automatically calls Rosetta translation via binfmt_misc. The container has no idea what's happening. Performance comparison: - Rosetta solution: close to 70-90% of native performance (JIT translation, instruction-level optimization) - QEMU full virtualization: only about 10-30% (full x86 CPU emulation) A kernel feature designed in 1997 for running Java class files became the key infrastructure for running x86 containers on Apple Silicon in 2024. Sometimes the most enduring architectural decisions are those that are simple enough and general enough as abstractions. $ colima ssh $ cat /proc/sys/fs/binfmt_misc/rosetta enabled interpreter /mnt/lima-rosetta/rosetta flags: OCF magic 7f454c4602010100000000000000000002003e00
Original Article
View Cached Full Text

Cached at: 06/05/26, 03:16 PM

Did you know that the Linux kernel has a feature introduced in 1997 that enables Apple Silicon Macs to efficiently run x86 containers?

It’s called binfmt_misc, introduced in Linux 2.1.43 — nearly 30 years ago.

The principle is extremely simple: When the Linux kernel executes a binary, it first reads the magic number from the file header. If you have registered a rule in /proc/sys/fs/binfmt_misc/ — “for files with this magic, hand them over to a specific interpreter” — the kernel automatically delegates execution to that interpreter. It’s essentially the same mechanism as #!/bin/bash (shebang), but it matches binary file headers instead.

Originally, it was used to let Linux directly “run” Java class files and Windows PE executables. Later, QEMU used this mechanism for user-mode cross-architecture emulation — on ARM Linux, executing an x86 ELF directly, with the kernel automatically invoking qemu-x86_64 to translate.

Then Apple came along. When you launch a Linux VM using Colima / Lima on an Apple Silicon Mac (using macOS’s Virtualization.framework) with rosetta: true enabled, the following happens:

  1. macOS mounts the Rosetta translator binary into the Linux VM’s /mnt/lima-rosetta/rosetta via virtio-fs
  2. Inside the VM, a standard binfmt_misc rule is registered: when encountering x86_64 ELF magic (7f454c46...02003e00), hand it over to /mnt/lima-rosetta/rosetta
  3. From then on, any execution of x86_64 binaries within the VM is automatically handed off to Rosetta for translation by the kernel

This is completely transparent to containers — docker run --platform linux/amd64 nginx: Docker pulls down an x86 image, the processes inside the container are x86 ELF binaries, and the Linux kernel automatically invokes Rosetta via binfmt_misc to translate and execute them. The container itself has no idea what’s happening.

Performance comparison:

  • Rosetta approach: approximately 70-90% of native performance (JIT translation, instruction-level optimization)
  • QEMU full virtualization approach: only about 10-30% (complete x86 CPU emulation)

A kernel feature designed in 1997 to run Java class files became, in 2024, the critical infrastructure for running x86 containers on Apple Silicon. Sometimes the most enduring architectural decisions are those that are simple and generic enough abstractions.

$ colima ssh
$ cat /proc/sys/fs/binfmt_misc/rosetta
enabled
interpreter /mnt/lima-rosetta/rosetta
flags: OCF
magic 7f454c4602010100000000000000000002003e00

Similar Articles

@sitinme: There's a pretty interesting open-source project called Cider, specifically designed to accelerate local AI inference on Macs with Apple Silicon chips. Many people buy a Mac mini or MacBook Pro and want to run models locally, but often encounter issues like insufficient speed and high memory usage. Actually...

X AI KOLs Timeline

Cider is an open-source project designed for Apple Silicon Macs, accelerating local AI inference by fully leveraging the computing power of M-series chips. It is compatible with the MLX ecosystem, supports models like Qwen and Llama, and is easy to install.

macOS Container Machines

Hacker News Top

Apple has released 'container', an open-source tool that lets macOS users create and run Linux containers as lightweight virtual machines, optimized for Apple silicon and supporting OCI-compatible images.