HN
Today

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.

12
Score
0
Comments
#2
Highest Rank
4h
on Front Page
First Seen
Mar 28, 5:00 PM
Last Seen
Mar 28, 8:00 PM
Rank Over Time
6233

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.gz script, revealing it to be a shell script that uses kexec to load a new kernel and ramdisk (both extracted from a base64-encoded cpio archive).
  • This loaded OS's init script then recursively creates a new cpio archive of its current state and kexecs itself, demonstrating a "recursive" Linux distro.
  • The core argument is that initrds are programs, and the Linux kernel acts as their interpreter, much like sh interprets shell scripts or python interprets Python scripts.
  • The recursive kexec is 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.2 acts 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_misc can be used to make cpio archives directly executable by registering a custom interpreter (a QEMU script or even a kexec script) 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.