Explore a modern implementation of the Linux 0.11 kernel, meticulously rewritten in Rust. This project keeps the original semantics while enhancing type safety and modular clarity. With a fully functional userland and one-command image building, it offers a unique development environment for enthusiasts and developers.
Overview
linux-0.11-rs is an innovative and modern rewrite of the Linux 0.11 kernel, created in idiomatic Rust. This project showcases the capabilities of Rust while maintaining the original system's semantics, effectively rethinking expressions through stronger types, clearer module boundaries, and idiomatic abstractions. It successfully boots on emulated i386 hardware and integrates a self-hosted Unix-style userland, bringing a historical kernel into the modern era.
Features
-
Complete Kernel Functionality: Experience most features of Linux 0.11 including process management, virtual memory with demand paging and Copy-On-Write (CoW) fork, Minix v1 filesystem support, ATA disk driver functionality, VGA and PS/2 console interface, serial console integration, TTY layer, signal handling, and a complete system call table.
-
Rust-based User Library: The
user_liboffers a robust interface mirroring the public shape ofstd::{fs, io, path, env, process, time}, allowing user programs to be written in a familiar Rust style rather than through cumbersome syscall plumbing. -
Comprehensive Userland: A rich set of over 80 core utilities is included along with a custom POSIX-subset shell (
sh). This shell supports pipelines, control flow, functions, globbing, command and arithmetic substitution, and features an interactive line editor equipped with Tab completion and command history. -
Effortless Disk Image Creation: The script
tools/build-disk.shcompiles all user programs, organizes them into a Unix-style filesystem, and packs them into a bootable disk image with a single command. -
Utility Tools: The project includes
mbrkitandminiximg, standalone crates that serve as valuable resources for any projects related to MBR or Minix v1 images. -
Built-in Development Environment: A
.devcontaineris provided, allowing users to clone the repository, open it in VS Code, and begin development immediately by runningmake run.
Getting Started
To engage with the project, the kernel can be built and run easily in QEMU with the following commands:
# Compile all user programs, structure file systems, and create a disk image.
tools/build-disk.sh
# Build the kernel and launch it in QEMU.
cd kernel && make run # For VGA console
cd kernel && make run-console # For serial console (-nographic)
Users will find themselves greeted by a shell prompt in /root. From there, a variety of commands can be utilized:
ls /bin # List installed binaries
echo $((1 + 2 * 3)) # Perform arithmetic
for f in /etc/*; do echo $f; done # Loop through files in /etc
fact() { if [ $1 -le 1 ]; then echo 1; else echo $(($1 * $(fact $(($1-1))))); fi; }
fact 7 # Calculate factorial
ec<TAB> # Utilize command completion
↑ # Navigate command history
Testing
To run end-to-end tests, the kernel boots under QEMU and interacts with the serial console via .ktest scripts found in ktest/suites/:
tools/run-tests.sh # Execute all tests
tools/run-tests.sh --suite=shell # Run single suite
tools/run-tests.sh --test-set=shell.basic # Run specific test
tools/run-tests.sh --disable-reboot # Share one QEMU instance across tests
Project Structure
The repository is organized as follows:
kernel/ # Kernel source code
user_lib/ # Standard-style user-space library
user_lib_macros/ # Proc-macro for #[user_lib::main]
user_program/ # ~80 core utilities and `sh` shell
ktest/ # End-to-end testing framework for QEMU
mbrkit/ # CLI for MBR disk imaging
miniximg/ # CLI and library for Minix filesystem
rootfs/ # Disk image content template
/tools/ # Developer scripts for building and testing
/tutorial/ # Documentation walkthrough (in progress)
.devcontainer/ # Development environment setup
Status and Future Development
While the kernel is largely feature-complete in comparison to Linux 0.11, ongoing work focuses on refinement and tooling enhancements rather than floppy support. The user library fulfills the necessary requirements for both the shell and core utilities, allowing meaningful interactive work in the existing userland. A complete tutorial is currently under development, with the aim of providing users with a build-from-scratch guide.
No comments yet.
Sign in to be the first to comment.