Exec Format Error
The kernel cannot execute the file because its format is unrecognized. This occurs when trying to execute a binary compiled for a different CPU architecture, or a script file that lacks a valid shebang line.
- 1Running an ARM binary on an x86_64 system without a compatibility layer.
- 2A script file is missing the shebang line (#!/bin/bash) at the top.
- 3The file has the execute bit set but contains plain text with no shebang.
- 4Trying to execute a 32-bit binary when 32-bit libraries are not installed.
Running an ARM binary on an x86_64 host without binfmt_misc/qemu.
$ ./arm_binary bash: ./arm_binary: cannot execute binary file: Exec format error
expected output
bash: ./arm_binary: cannot execute binary file: Exec format error
Fix 1
Add a shebang line to script files
WHEN When a script file is not executable because it lacks a shebang
#!/usr/bin/env bash set -euo pipefail echo "Hello from the script"
Why this works
The shebang line tells the kernel which interpreter to use. Without it, the kernel tries to execute the file directly and fails.
Fix 2
Install binfmt_misc and qemu to run cross-arch binaries
WHEN When running Docker images or binaries for a different architecture
# Install QEMU user-mode emulation sudo apt-get install qemu-user-static docker run --platform linux/arm64 arm64v8/ubuntu uname -m
Why this works
binfmt_misc registers QEMU as the interpreter for foreign architecture binaries.
Linux Programmer Manual errno(3)
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev