Linux Running Inside a PDF via RISC-V Emulator
Linux Running Inside a PDF File via a RISC-V Emulator
Video: GitHub - ading2210/linuxpdf: Linux running inside a PDF file via a RISC-V emulator
This innovative project, created by ading2210, demonstrates how to run Linux inside a PDF file using a RISC-V emulator. The project is based on TinyEMU, a lightweight RISC-V emulator, and leverages the capabilities of JavaScript within PDF files to achieve this feat.
How It Works
The PDF file format supports JavaScript with a limited set of APIs, which can be used to perform computations and interact with the user. Modern browsers (like Chromium and Firefox) implement these APIs as part of their PDF engines. The project compiles a modified version of the TinyEMU RISC-V emulator to asm.js, which can then be run within the PDF file.
Key Features
- Emulation: The RISC-V emulator runs a Linux kernel inside the PDF file.
- Display: The display is implemented using text fields, where each row of pixels is represented by ASCII characters.
- Input: A virtual keyboard is provided for user input, and a text box allows for sending keystrokes to the virtual machine.
- Performance: The Linux kernel takes about 30-60 seconds to boot up within the PDF, which is over 100 times slower than normal due to the limitations of the JavaScript engine in browsers.
- Root Filesystem: Both 32-bit and 64-bit versions are available, with the 32-bit version being the default due to better performance.
Build Instructions
To build the project, follow these steps:
- Clone the repository from GitHub.
- Run the following commands:
python3 -m venv .venv source .venv/bin/activate pip3 install -r requirements.txt ./build.sh - If you want to build the 64-bit version, edit the
build.shscript and change theBITS="32"line toBITS="64". - The generated files will be in the
out/directory. You can serve these files using a web server:(cd out; python3 -m http.server)
Credits
This project was created by ading2210. The RISC-V emulator is a fork of TinyEMU, originally written by Fabrice Bellard.
License
The project is licensed under the GNU GPL v3.