KFS — Kernel From Scratch
This is the complete documentation for building a bare-metal i386 kernel in Rust, written as it was actually built — including the wrong turns, the debugging sessions at 5am, and the moments where everything finally clicked.
The Kernel From Scratch (KFS) series is a 42 school project, but the documentation here goes far beyond what the subject requires. Every concept is explained from first principles. Every decision has a “why”. Every bug that caused a headache has its own section.
What This Is
A working reference for anyone building or studying a kernel from scratch in Rust. Not a tutorial that skips the hard parts — a complete record of what it actually takes.
What You’ll Build
By following through all three projects:
- A kernel that boots via GRUB on i386 bare metal
- VGA text mode output with color, scrolling, and cursor control
- Interrupt-driven keyboard input
- A proper interrupt subsystem (IDT + PIC + exception handlers)
- A Global Descriptor Table (GDT) with kernel and user segments
- An interactive shell
- A working memory paging system with frame allocation
How to Use This Book
Each chapter documents a concept at the theory level first, then walks through the implementation in Rust. Code examples are taken directly from the actual kernel source.
The debugging chapters are not optional reading — they contain the lessons that can’t be found in any spec.
Prerequisites
- Basic Rust knowledge (ownership, unsafe, no_std)
- Comfortable reading x86 assembly
- A Linux system with QEMU and NASM installed
Built with 🦀 Rust, fuelled by too much coffee, and the eternal optimism that this time it won’t triple fault.