Linux runs in PDF

Doom runs on everything, including PDF – Why not Linux? A tinkerer thought so and started a minimal system in the PDF-RISCV emulator.

listen Print view
Linux running in PDF document

Linux starts in PDF document

(Image: Screenshot / dmk)

3 min. read

Resourceful inventors have proven time and again that the game “Doom” can run on anything – perhaps apart from a slice of salami, but who knows what else is coming –. Now, however, one of them has put the Linux kernel into a PDF – not as source code for reading, but as a bootable operating system.

The starting point for the successful attempt was the Doom port to PDF, which was made public in mid-January. The hobbyist ading2210 explains that LinuxPDF works in a very similar way. The starting point is Javascript, which is supported in the PDF format. The implementations in modern web browsers such as Chrome and Firefox are limited, unlike Adobe PDF, they only support a subset of all APIs – due to security concerns. However, this is enough to perform any calculation you want, just with quite limited input and output.

An old version of Emscripten (an LLVM-to-web compiler) can spit out the result as an “asm.js” target instead of WebAssembly. This allowed ading2210 to compile a modified version of the TinyEMU RISCV emulator to “asm.js”. And this runs in the PDF document.

Videos by heise

For the input and output, ading2210 has reused the code from DoomPDF. Each row of pixels represents a separate text field whose content is generated by numerous ASCII characters. A virtual keyboard is available for input. The easiest way is to use the text field provided for input.

ading2210 describes the performance of the emulator as the biggest problem. The Linux kernel takes 30 to 60 seconds to start, which is more than a hundred times slower than normal. Nothing can be done about this, as the just-in-time compiler in the Chrome PDF component is stalled in the current version of the Javascript engine V8, which is detrimental to speed.

The programmer ading2210 explains that both 32-bit and 64-bit versions are possible as the root file system. The 32-bit buildroot system, which originates from the TinyEMU examples, starts as standard. A 64-bit Alpine Linux system is also available, but it only achieves half the speed, which is why it is not normally used. Interested parties can fork and edit the sources in the GitHub project, which is licensed under GPLv3. The LinuxPDF can also be tried out directly there.

(dmk)

Don't miss any news – follow us on Facebook, LinkedIn or Mastodon.

This article was originally published in German. It was translated with technical assistance and editorially reviewed before publication.