Skip to content

From Zero to Self-Hosting: 132,670 Lines of Rust OS, Built Entirely with AI

What happens when you sit down with an AI and say “let’s build an operating system from scratch”? You get MerlionOS: 132,670 lines of Rust, 100 versions, 4 CPU architectures, and a kernel that can compile itself — built entirely through human-AI collaboration.

MetricValue
Lines of Rust132,670
Modules~360
Shell commands480+
CPU architectures4 (x86_64, ARM, RISC-V, LoongArch)
Releases100 (v1 through v100)
Compiler errors0
Compiler warnings0
Floating point usage0 (all integer/fixed-point math)

The project started as a simple “boot and print hello” exercise and grew into a complete operating system over 100 versions:

v1 7 lines Hello World
v10 7,000 lines Multitasking, shell, IPC
v26 41,000 lines AI-native OS, networking, servers
v45 51,000 lines Microkernel mode, GPU, Bluetooth
v60 65,000 lines Procfs, sysfs, ACLs, power management
v77 82,000 lines Vim editor, bash/zsh, 4 CPU architectures
v87 121,000 lines Window compositor, desktop environment
v92 125,000 lines Web browser, email client, music player
v97 130,000 lines PAM, OCI containers, KVM virtualization
v100 133,000 lines LLM inference, AI admin, self-hosting compiler

The networking subsystem alone spans 9 development phases and ~25,000 lines:

  • Protocols: HTTP/1.1, HTTP/2, HTTP/3 (QUIC), gRPC, FTP, TFTP, SSH, SMTP, IMAP, MQTT, WebSocket
  • Services: DNS server, DHCP server, NTP client, mDNS/DNS-SD, SOCKS5 proxy, HTTP proxy
  • Security: TLS 1.3, WireGuard VPN, iptables/NAT, ufw firewall
  • Routing: OSPF, BGP, RIP, VLAN 802.1Q
  • Advanced: TCP Fast Open, SACK, eBPF/XDP, DPDK-style polling, Raw sockets, BPF
  • NICs: e1000e, virtio-net, RTL8139, RTL8169, Intel I225-V 2.5GbE
  • QoS: Traffic shaping (tc/qdisc), DSCP/ECN marking
  • Monitoring: SNMP agent, RADIUS authentication, IGMP multicast

A complete graphical desktop built on a framebuffer rendering engine:

  • Window compositor with virtual desktops, Alt+Tab, taskbar
  • Desktop icons, application launcher, system tray (clock, battery, network, notifications)
  • File manager with multiple views, sort, filter, preview
  • System settings (10 categories), network manager
  • Themes with Merlion gold accent 🦁
  • Web browser: HTML parser (25 tags), CSS parser, block/inline layout engine
  • Email client: SMTP send, IMAP receive, mailbox management
  • Music player: WAV playback, playlist, equalizer, VU meter
  • Vim editor: Normal/Insert/Visual/Command modes, undo/redo, registers, search
  • Development environment: Syntax highlighting for 10 languages, build integration
  • Games: Snake, Tetris, calculator, painting app
  • LLM inference in-kernel: GGUF model loading, INT4/INT8 quantized matrix multiply, full transformer (RMSNorm, RoPE, multi-head attention, FFN), KV cache, BPE tokenizer, top-k/top-p sampling — all in integer arithmetic, no floats, no GPU
  • AI system administrator: Anomaly detection, auto-diagnosis, performance auto-tuning, natural language configuration (“allow port 80” → ufw allow 80), predictive maintenance, security audits
  • Neural network training: Linear regression, decision trees, KNN — all fixed-point
  • AI self-evolution: The kernel analyzes its own source code, generates findings, and suggests patches

v100 includes a Rust subset compiler, x86_64 assembler, and ELF linker — the OS can compile programs:

  • Lexer: 25 Rust keywords, 18 token types
  • Parser: Functions, let/assignment, if/else, while, match, structs, enums → AST
  • Code generator: AST → x86_64 assembly instructions
  • Assembler: mov, add, sub, mul, cmp, jmp, call, ret with REX prefix encoding
  • Linker: Generate minimal ELF64 executables

The entire OS was built through conversation with Claude (Anthropic’s AI). The workflow:

  1. Describe the goal: “Add OSPF routing protocol” or “Implement iptables-style packet filter”
  2. AI generates code: Claude writes 300-1000 lines of complete, compilable Rust
  3. Parallel execution: 5-7 AI agents building different modules simultaneously
  4. Build and test: cargo build — fix any issues — make run — verify in QEMU
  5. Commit and push: Every working milestone gets committed

A typical session produces 10,000-20,000 lines of new code across 10-20 modules. The v27→v100 journey (41K → 133K lines) happened in a few conversation sessions.

  • Rust’s type system catches bugs: No null pointers, no buffer overflows, no data races — the compiler catches what the AI misses
  • no_std constraints: Every module must compile without standard library — this forces clean, self-contained code
  • Parallel agents: Independent modules (e.g., OSPF and SMTP) can be built simultaneously without conflicts
  • Immediate feedback: cargo build tells us within seconds if something is wrong

The entire 133K-line codebase uses zero floating point operations. Everything — including neural network inference, audio synthesis, graphics rendering, and network timing — uses integer or fixed-point arithmetic. This means:

  • No FPU state to save/restore on context switch
  • Deterministic behavior (no rounding surprises)
  • Works on CPUs without FPU (embedded, early boot)

The same kernel core runs on x86_64, aarch64 (Raspberry Pi), RISC-V, and LoongArch (龙芯). Architecture-specific code is isolated behind #[cfg(target_arch)]:

Terminal window
make build # x86_64
make pi # Raspberry Pi
make riscv # RISC-V
make loongarch # LoongArch (龙芯)

MerlionOS boots on real x86_64 hardware via the Limine bootloader:

Terminal window
make iso # Build bootable ISO
# Write to USB, boot any x86_64 PC with UEFI

Tested on QEMU with UEFI firmware — all subsystems initialize, framebuffer displays at 1280×800.

The v1-v100 roadmap is complete. But there’s always more to build:

  • Real hardware testing on diverse machines (HP, Dell, Lenovo, Raspberry Pi 4/5)
  • GPU compute — real AMD RDNA3 driver for GPU-accelerated inference
  • Community — if people are interested, making it contributor-friendly
  • Performance — the code works but hasn’t been optimized for speed

MerlionOS is named after the Merlion (鱼尾狮), Singapore’s iconic half-lion half-fish statue. The tagline “Born for AI. Built by AI” (生于AI,成于AI) reflects that this OS was conceived for AI workloads and constructed entirely through AI collaboration.

Terminal window
git clone https://github.com/MerlionOS/merlion-kernel.git
cd merlion-kernel
make build && make run
# Login: root (empty password)
# Type: help

Built with Claude Opus by Larry in Singapore 🇸🇬

Born for AI. Built by AI. Compiles itself. 🦁