xv6-riscv: MIT’s Beautiful Minimalist OS That Taught Me How Kernels Really Work

xv6-riscv is a clean, minimalist, educational operating system developed by MIT. It is a re-implementation of the historic Unix Version 6 (1975) written in ANSI C for the modern RISC-V architecture.

Purpose

  • To teach core operating system concepts through a small, readable, and runnable codebase (~10,000 lines).
  • Used primarily in MIT’s 6.1810 Operating System Engineering course.
  • Bridges theory and practice — students can read, understand, and modify every part of a real OS.

Why It’s Valuable

  • Simple enough to comprehend fully, yet complete enough to demonstrate real OS behavior (processes, virtual memory, file systems, traps, concurrency, etc.).
  • Runs efficiently in the QEMU emulator.
  • Excellent companion book explains the code line-by-line.

How to Use It

  1. Clone the repo: git clone https://github.com/mit-pdos/xv6-riscv.git
  2. Install RISC-V toolchain + QEMU
  3. Run with make qemu
  4. Modify kernel code and recompile to experiment

Structured 4-Week Learning Roadmap

Week 1: Boot, Setup & Big Picture

  • Read Book Chapter 1–2
  • Understand boot process (entry.S, start.c, main.c)
  • Run make qemu, explore basic shell commands
  • Read kernel initialization code

Week 2: Processes & System Calls

  • Book Chapters 3–4
  • Study proc.c, syscall.c, sysproc.c
  • Lab: Add a new system call
  • Understand fork(), exec(), traps

Week 3: Memory Management

  • Book Chapter 5
  • Study page tables, vm.c, kalloc.c
  • Lab: Implement copy-on-write or lazy allocation
  • Understand address spaces and virtual memory

Week 4: File System & Advanced Topics

  • Book Chapter 6–8
  • Study fs.c, bio.c, log.c
  • Lab: Add a file system feature or scheduler improvement
  • Explore traps, devices, and locking

Ongoing:

  • Run usertests frequently
  • Use GDB (make qemu-gdb)
  • Read the original Lions’ Commentary on Unix v6 for deeper insight