Linux Is an Interpreter
This piece playfully argues that Linux acts as an interpreter for initrds, proving its point by crafting a recursive Linux distribution that kexecs itself. It then expands on this idea, demonstrating how even ELF binaries are 'interpreted' by ld.so, ultimately showing how a cpio archive can become an executable. This deep dive into operating system internals and the nature of execution perfectly tickles the brain of a Hacker News reader.
The Lowdown
The article "Linux Is an Interpreter" delves into the philosophical and practical nature of execution within Linux, provocatively arguing that the Linux kernel itself functions as an interpreter for initrds. It builds on a previous series by demonstrating a self-rebooting Linux distribution, then extends the "interpreter" analogy to ELF binaries and dynamic linkers.
- The author reverse-engineers a mysterious
rkx.gzscript, revealing it to be a shell script that useskexecto load a new kernel and ramdisk (both extracted from a base64-encodedcpioarchive). - This loaded OS's
initscript then recursively creates a newcpioarchive of its current state andkexecs itself, demonstrating a "recursive" Linux distro. - The core argument is that initrds are programs, and the Linux kernel acts as their interpreter, much like
shinterprets shell scripts orpythoninterprets Python scripts. - The recursive
kexecis likened to a tail-call-optimized recursive function, where each "stack frame" (Linux instance) replaces the previous one without accumulating. - The concept of a "quine" is introduced, and the author shows how their recursive Linux could be modified to be an initrd quine—a self-reproducing OS.
- The article further explores the idea of interpretation by analyzing ELF binaries, noting that
ld-linux-x86-64.so.2acts as an interpreter for dynamically linked ELFs. - The base case for this interpretation chain is the kernel itself, which directly interprets statically linked ELFs like
ld.so. - Finally, the author demonstrates how
binfmt_misccan be used to makecpioarchives directly executable by registering a custom interpreter (a QEMU script or even akexecscript) that treats them as OS images. - This leads to the "strangest loop": an initrd that registers an interpreter making other initrds executable, effectively turning the next reboot's kernel into the interpreter for the current one, without bottoming out the interpretation chain.
Through these intricate examples, the article challenges conventional understandings of what constitutes a "program" and an "interpreter" within the Linux ecosystem, presenting a highly technical yet conceptually engaging exploration of system boot processes and execution models.