用地道的 Rust 重写的 Linux 0.11,可在 QEMU 中启动。
Linux 0.11 rewritten in idiomatic Rust, boots in QEMU

原始链接: https://github.com/Poseidon-fan/linux-0.11-rs

**linux-0.11-rs** 是对 1991 年经典 Linux 0.11 内核的现代 Rust 重写。通过将 Rust 的内存安全特性和地道抽象应用于原始架构,它在保留 1991 年系统核心语义的同时,提供了一个更健壮、更易于维护的代码库。 该项目功能完备,能够在模拟的 i386 硬件(QEMU)上启动,并运行完整的类 Unix 环境。主要特性包括: * **功能完整的内核:** 实现了进程管理、带按需分页的虚拟内存、写时复制(CoW)fork、Minix v1 文件系统以及必要的驱动程序(ATA、VGA、PS/2、串口)。 * **Rust 用户态:** 自定义的 `user_lib` 允许使用地道的 Rust 而非原生系统调用来编写用户程序。 * **丰富的生态系统:** 包含 80 多个核心工具,以及一个支持管道、通配符和交互式行编辑的 POSIX 子集 Shell。 * **开发者友好:** 提供一键构建工具、磁盘镜像生成器(`mbrkit`、`miniximg`)以及预配置的 Devcontainer,开箱即用。 该存储库专为教育探索和技术实验而设计,提供了一个完整的环境,让用户能够利用现代系统编程实践来重构并体验这一 Linux 历史基石。

最近一篇 Hacker News 帖子介绍了一个用地道的 Rust 重写 Linux 0.11 内核的项目,该项目已成功在 QEMU 中启动。 社区对此反应不一。一些用户质疑,为何 Rust 版本需要约 50,000 行代码(SLOC),而原版 C 语言仅需 8,000 到 12,000 行。随后引发了关于代码量差异来源的讨论,评论者们提出了多种看法: * **冗长与显式:** 有人认为,Rust 的固有冗长是为了换取更高的代码安全性和显式表达。 * **工程优先级:** 持怀疑态度者认为,代码量增加可能是出于对可量化影响的追求,而非代码效率。 * **主观因素:** 另一些人则称该项目为“垃圾软件”(slopware),或批评了其 README 文档的美学选择。 尽管存在技术层面的批评,该项目作为将传统内核代码移植到现代内存安全语言的一次尝试,仍具有显著的实验意义。
相关文章

原文

A modern Rust rewrite of the Linux 0.11 kernel — boots on i386 in QEMU, runs a self-hosted Unix-style userland.

$ cd kernel && make run
…
Welcome to linux-0.11-rs.
https://github.com/Poseidon-fan/linux-0.11-rs
(login: 0 @ linux-rs :: Wed May 27 09:35:43 UTC 2026)
[root@linux-rs /root]# ls /bin | wc -l
69

linux-0.11-rs rebuilds the 1991 Linux 0.11 kernel from scratch in modern Rust. It keeps the original system's semantics — what it does — while rethinking how it's expressed: stronger types, clearer module boundaries, idiomatic abstractions everywhere. The kernel boots on emulated i386 hardware, runs a full init → shell → coreutils stack, and ships with the tooling to build your own bootable image in one command.

  • A kernel with most of what Linux 0.11 had — processes, virtual memory with demand paging and CoW fork, the Minix v1 filesystem, ATA disk driver, VGA + PS/2 console, 8250 serial console, TTY layer, signals, and the complete syscall table.
  • A Rust user-space "std"user_lib mirrors the public shape of std::{fs, io, path, env, process, time} so user programs read like ordinary Rust, not like syscall plumbing.
  • A real userland — 80+ coreutils plus a hand-written POSIX-subset shell (sh) with pipelines, control flow, functions, glob, command and arithmetic substitution, and an interactive line editor with Tab completion and history.
  • One-command imagestools/build-disk.sh compiles every user program, lays them out into a Unix-style filesystem, and packs the result into a bootable disk image.
  • Companion image toolsmbrkit and miniximg are standalone crates, useful on their own for any project that touches MBR or Minix v1 images.
  • Devcontainer included — clone, open in VS Code, hit "Reopen in Container", run make run.
# Build every user program, lay out /etc /dev /bin, pack into disk.img.
tools/build-disk.sh

# Build the kernel and boot it in QEMU.
cd kernel && make run            # VGA console
cd kernel && make run-console    # serial console (-nographic)

You'll land at a shell prompt in /root. Try:

ls /bin                              # browse what's installed
echo $((1 + 2 * 3))                  # arithmetic expansion
for f in /etc/*; do echo $f; done    # for loop + glob
fact() { if [ $1 -le 1 ]; then echo 1; else echo $(($1 * $(fact $(($1-1))))); fi; }
fact 7                               # → 5040
ec<TAB>                              # completes to `echo `# walks command history

Outside a devcontainer you'll also need a recent Rust nightly (pinned in rust-toolchain.toml), qemu-system-i386, the x86_64-linux-gnu-* cross-binutils, and the local image/test tools:

tools/install-tools.sh        # installs mbrkit, miniximg, ktest onto PATH

End-to-end tests boot the kernel under QEMU and drive the serial console from short .ktest scripts under ktest/suites/.

tools/run-tests.sh                              # run everything
tools/run-tests.sh --suite=shell                   # one suite
tools/run-tests.sh --test-set=shell.basic          # one test
tools/run-tests.sh --disable-reboot             # share one QEMU across tests

🗂️ Repository layout

kernel/              The kernel itself
user_lib/            std-style user-space library
user_lib_macros/     proc-macro: #[user_lib::main]
user_program/        ~80 coreutils + the `sh` shell
ktest/               end-to-end test runner driving QEMU over serial
mbrkit/              MBR disk-image CLI (also on crates.io)
miniximg/            Minix-fs image CLI and library
rootfs/              disk-image content template (/etc, /root, …)
tools/               developer scripts (build-disk.sh, run-tests.sh, …)
tutorial/            mdbook walkthrough (work in progress)
.devcontainer/       ready-to-use dev environment
  • Kernel — substantially feature-complete relative to Linux 0.11. Floppy support is intentionally out of scope; ongoing work is on polish and tooling.
  • User library — covers what the shell and coreutils need today.
  • Userland — usable for real interactive work.
  • Tutorial — early draft; the long-term plan is a complete build-from-scratch walkthrough.
cargo install mdbook
cd tutorial && mdbook serve --open
  • Thanks to yuan-xy/Linux-0.11 for providing the original Linux 0.11 kernel source used as an important reference during development.
  • Many parts of this project were also inspired by or implemented with reference to rcore-os/rCore-Tutorial-v3.

See LICENSE.

联系我们 contact @ memedata.com