Linux 0.11 Rewritten in Idiomatic Rust: Modernizing a Classic Kernel for i386 QEMU
The `linux-0.11-rs` project delivers a modern, type-safe rewrite of the 1991 Linux 0.11 kernel, complete with demand paging, CoW fork, a Minix v1 filesystem, and a self-hosted userland. The architecture features an alternative standard library mimicking the Rust `std` API alongside over 80 core utilities and a custom POSIX-subset shell.
Kernel Architecture and Memory Management
The `linux-0.11-rs` kernel implements the exact semantics of the original 1991 release while replacing raw C structures with idiomatic Rust abstractions. Written primarily in Rust (97.2%) with minimal Assembly (1.2%) for low-level bootstrapping, the codebase enforces strict module boundaries and type safety across subsystems.
Memory management in the kernel implements virtual memory with demand paging and Copy-on-Write (CoW) page allocation during process duplication via `fork`. It supports the complete original system call table, a full TTY layer, and POSIX signal handling. Storage and input-output are managed through an Integrated Drive Electronics (IDE) style ATA disk driver, a standard 8250 serial console, and a VGA and PS/2 input console driver. Floppy disk drive support has been intentionally excluded from the project's scope to prioritize modern clean room abstraction design.
For storage layout, the kernel mounts a Minix v1 filesystem. Rather than relying on legacy host utility behavior, the codebase utilizes standalone tools to facilitate disk generation.
The user_lib Runtime and User-Space Architecture
To avoid forcing user-space programs to interface directly with raw system calls, the project introduces `user_lib`. This crate acts as an alternative standard library specifically tailored for the target kernel environment.
- `std::fs` for filesystem interactions
- `std::io` for buffered read and write operations
- `std::path` for path manipulation
- `std::env` for environment variable access
- `std::process` for process spawning and control
- `std::time` for system clock queries
Execution entry points in user space are managed through a procedural macro, `#[user_lib::main]`, defined in the `user_lib_macros` crate. This macro abstracts away the low-level stack setup and argument parsing, allowing user-space programs to look and feel like standard Rust binaries.
Userland and Shell Implementation
The user-space environment is entirely self-hosted, containing over 80 core utility programs alongside a custom POSIX-subset shell named `sh`.
- Full pipeline execution and job controls
- Shell control-flow structures and custom functions
- Glob expansion and filename pattern matching
- Command and arithmetic substitution
- An interactive line editor featuring command history and Tab completion
The entire utility suite compiles alongside the kernel. The repository contains templated root filesystem structures in the `rootfs/` directory, which include typical UNIX configurations like `/etc` and `/root`.
Build System and Automated Testing
- `mbrkit`: A standalone CLI tool for managing Master Boot Record (MBR) partition tables on disk images.
- `miniximg`: A Minix v1 filesystem image generator and library.
Using the unified `tools/build-disk.sh` script, the build system automatically compiles every user program, populates the target directory layout, and generates a bootable raw disk image. The kernel is booted under QEMU utilizing an x86_64 cross-compilation toolchain and a pinned nightly Rust compiler.
End-to-end integration testing is managed by the `ktest` harness. It launches the compiled kernel inside QEMU, establishes a serial connection, and runs scripted testing scenarios defined in `.ktest` files to validate kernel and shell behaviors.