HN 展示:从零编写的自定义 X64-86 操作系统
Show HN: Custom X64-86 Operating System Written from Scratch

原始链接: https://github.com/adriantips/boltossource

BoltOS 是一个用 C 和汇编从零编写的业余操作系统,拥有自己的引导加载程序、内核、驱动程序、文件系统、TCP/IP/TLS 协议栈、桌面、浏览器引擎、编译器、shell 和应用,不使用 GRUB、Linux 内核或外部 libc。它以三个版本发布,共享大部分代码:面向 x86-64 PC/虚拟机的 Desktop,面向 HDMI 电视盒子的 TV,以及面向 Orange Pi Zero3 AArch64 的 Mini。所有版本均从 BoltOS 自有的 512 字节 MBR 或 UEFI 加载器启动;安装程序可以创建同时支持 MBR 和 UEFI 启动的磁盘。亮点包括 BoltFS、FAT32/EXT2 支持、带证书验证的 HTTPS、SSH 客户端/服务器、Wi-Fi 客户端、USB/xHCI 和音频驱动、MP3/H.264/AAC 解码、带 40 多个应用的合成桌面,以及本机 C/Python 开发,包含编译器、汇编器、链接器、调试器、VCS、软件包和 man 手册页。TV 提供流媒体应用、六个电影频道、Firefox 直通和 DNS 广告拦截。Mini 在 U-Boot 之后快速启动,在空闲核心上的 Linux 客户机中运行 Firefox,并支持本地 AI 和未经修改的 aarch64 musl 程序。该项目包含 69 个测试脚本、在主机侧与 mpg123、ffmpeg、NASM 和 binutils 等工具进行的对比,以及模糊测试。构建需要 clang、ld.lld、NASM 和 Python 3;镜像发布于 boltos.dev。

一篇 HN 帖子展示了 BoltOS,这是 adrianbyte 开发的一款业余操作系统,面向 x86-64 桌面,以及通过 U-Boot 启动的 Orange Pi Zero 3 ARM。该项目约 17 万行代码,包含自研内核、桌面 UI、SSH 支持和驱动程序;作者称其大部分代码为手写,AI 仅用于网站和部分 UI。评论者称赞其雄心,但质疑“从零开始”和“10% AI”的说法,理由包括提交速度很快、驱动程序规模庞大,以及代码看起来与现有开源软件有相似之处。建议包括将其改为微内核、加入 Plan 9 风格的命名空间、探索 Unikernel/WASM 思路、单独发布内核,以及专注于安全性和实时特性。还有人问到 POSIX 兼容性、SSH 互操作性、测试和内存安全,以及初学者如何学习操作系统和引导加载程序开发。总体而言,讨论串中既有对项目的热情,也有对其代码来源的怀疑,同时还呼吁提供更清晰的文档和更有新意的设计目标。
相关文章

原文

BoltOS is a hobby operating system written from scratch in C and assembly. It has its own bootloaders, kernel, drivers, filesystem, network stack, desktop, web browser engine and compilers. There's no GRUB, no Linux kernel and no outside libc. The only third-party code is a handful of vendored libraries, listed at the bottom.

BoltOS desktop

It comes in three editions that share most of their code:

Edition Runs on Docs Build
Desktop x86-64 PCs and VMs, BIOS or UEFI GUIDE.md bash build.sh
TV a small x86-64 PC on a TV's HDMI port TV.md bash build-tv.sh
Mini Orange Pi Zero3 (AArch64) MINI.md bash build-mini.sh

Prebuilt images are at boltos.dev/download, and more screenshots are in the gallery.

  • Boots from its own 512-byte MBR or its own UEFI loader. The installer can write a copy of the running system to a blank disk that then boots on both.
  • Loads real HTTPS sites over its own TCP/IP and TLS 1.3 stack, checking the certificate chain on the way.
  • A stock OpenSSH client can log in to its SSH server, and its SSH client can log in to another BoltOS.
  • The MP3 decoder matches mpg123 to within one least significant bit across 25 test files. Mini's H.264 decoder is bit-exact with ffmpeg on YouTube's streams.
  • You can write, assemble, link, debug and package programs on the machine itself. The assembler's output is byte-compared with NASM, and binutils reads the objects its linker writes.
  • Mini is up a quarter of a second after U-Boot hands over. It runs real Firefox in a Linux guest on its own small hypervisor, and a language model on the Pi's own cores.
  • 69 test scripts, host-side unit tests, and a fuzzer that has found and fixed 11 bugs in code a web page or a server gets to feed.

The desktop is a compositing window manager with a dock, a Start menu that searches apps, settings and files, Quick Settings, a notification centre, window snapping to halves and quarters, four virtual desktops and display scaling. It has over 40 apps:

  • System: Terminal, File Explorer, Settings, Task Manager, Device Manager, System Info, Network, Mixer, Logs, Security, Software (packages), Install BoltOS
  • Internet: Browser, OldBrowser (a NetSurf port)
  • Everyday: Code (an IDE), Notes, Sheets, Contacts, Tasks, Calendar, Calculator, Clock, Stopwatch, Photos, Paint, Color Picker, Snipping Tool, Character Map, Clipboard history
  • Media: Media (WAV and MP3), Music, Piano
  • Games: DOOM, BoltStrike, a Game Boy emulator, boltcraft, Solitaire, Minesweeper, Snake, 2048, Tic-Tac-Toe, Memory, Game of Life, Matrix

All screenshots are QEMU screendumps at 1920x1080.

A few things to try in the Terminal

sysinfo                              what the machine found
cc -N hello.c -o hello && run hello  compile C to x86-64 and run it
cc -g bug.c                          the same program under the debugger
vcs init && vcs add . && vcs commit -m "first"
pkg install cproject                 a starter project, headers and all
build /home/Documents/newproj        build and run it
sudo sshd                            let another machine log in
serve 8080 /home                     share a folder over HTTP
download https://example.com/a.mp3 && play a.mp3
display scale 200%                   for a 4K screen
screenshot                           a PNG in ~/Pictures

help lists every command, and man COMMAND explains one.

A rough list of what's implemented, by area. Most of it is in kernel/, drivers/, net/ and fs/.

Boot

  • BIOS boot chain: a 512-byte MBR (boot/stage1.asm) and a real-mode stage2 that sets up paging and enters long mode
  • UEFI loader (boot/uefi_boot.c, built as BOOTX64.EFI)
  • Boot menu with normal, safe mode, recovery shell and forced fsck
  • Higher-half kernel, linked at 0xFFFFFFFF80100000 and loaded at 1 MiB
BIOS -> stage1 (MBR, 0x7C00) -> stage2 (0x8000, real mode)
          boot menu, boot header at LBA 33, A20, E820 map,
          kernel to 1 MiB, page tables, long mode
     -> kernel/boot.asm -> kmain(bootinfo)

UEFI -> BOOTX64.EFI
          GOP framebuffer, memory map, page tables, long mode
     -> kernel/boot.asm -> kmain(bootinfo)

Core

  • ACPI tables, local APIC and IO-APIC, HPET, SMP bring-up of the other cores
  • Preemptive round-robin scheduler, ring-3 processes loaded from ELF64, syscall-based ABI (see SDK.md)
  • Paging with ASLR, SMAP and SMEP, swap, per-process address spaces
  • A ring-3 fault kills the process instead of the machine; crashes go to /var/log/crash.log, and ring-3 crashes also leave a core dump that core show turns into a named backtrace
  • Suspend to RAM (ACPI S3) and resume
  • Stack canaries, a watchdog thread, a kernel log ring (dmesg) that is saved across reboots
  • Runs Windows x86-64 console .exe files through a small kernel32 shim

Storage

  • ATA/IDE, AHCI SATA, NVMe (with MSI/MSI-X), virtio-blk and USB mass storage over xHCI
  • BoltFS, the native filesystem: two image slots, a mirrored superblock and cache flushes, so a power cut leaves either the old image or the new one. fsck checks it.
  • FAT32 read/write, EXT2 read-only
  • An installer (install, or the Install BoltOS app) that writes a system bootable on both BIOS and UEFI, from inside a running BoltOS

Networking

  • Intel e1000, e1000e (82571-82574, I217-I219) and igb (82575/82576, I210, I350), Realtek RTL8139 and RTL8111/8168/8169, AMD PCnet, NE2000 and virtio-net. Their match tables are generated from pci.ids at build time (176 Intel parts alone); all but the RTL8111/8168 run in test/t_nics.py
  • USB Ethernet: CDC-ECM and RNDIS, both run against QEMU's usb-net in test/t_usbnet.py, plus Realtek RTL8152/8153 and ASIX AX88179, which have never met a real chip
  • IPv4 and IPv6 (SLAAC, Neighbour Discovery), TCP, UDP, DHCP, DNS with a cache and /etc/hosts, SNTP
  • TLS 1.2 and 1.3 (X25519 and P-256, AES-GCM) with certificate chain verification (RSA PKCS#1 v1.5 and PSS, ECDSA P-256 and P-384)
  • HTTP/1.1 client with cookies, redirects, keep-alive and gzip
  • Sockets for ring-3 programs, a firewall, and serve, a small HTTP file server
  • SSH-2 server and client (curve25519-sha256, ecdsa-sha2-nistp256, aes128-ctr, hmac-sha2-256)
  • An 802.11 client with WPA2-PSK and CCMP. There's no driver for a real Wi-Fi card yet, so it's tested against a simulated access point that runs inside the kernel.

Graphics and input

  • PCI display detection and mode setting through the Bochs VBE interface (QEMU, VirtualBox), up to 4K, with 100-200% scaling
  • A compositor that only redraws what changed, and a glass-style shell
  • Its own TrueType rasteriser for Inter and DejaVu Sans Mono
  • PNG, JPEG, GIF and BMP decoding; a PNG encoder for screenshots and animated PNG for screen recording
  • xHCI USB with hubs, HID keyboards and mice, and report-protocol pointers (USB tablets, many gaming mice); virtio keyboards and tablets; PS/2
  • USB serial adapters as ttyUSB0 and on, read and written with usb serial: FTDI (tested against QEMU's usb-serial), and CDC-ACM, CP210x, CH340/CH341 and PL2303 (untested). Chip tables come from usb.ids
  • lspci and lsusb name every device from pci.ids / usb.ids, and Device Manager shows which driver owns each one
  • Rebindable global shortcuts, and keyboard layouts for us, us-intl, uk, de, fr, es, it and se (AltGr and dead keys included)

Audio

  • Intel HDA, AC'97, and the PC speaker as a fallback
  • WAV playback and an MP3 decoder (MPEG-1, 2 and 2.5 Layer III)
  • A per-channel mixer and microphone recording

Web

  • A browser engine: HTML tokenizer and DOM, CSS cascade, block/inline, flexbox and grid layout
  • BoltJS, a JavaScript interpreter with DOM bindings, events, timers, fetch() and Promises
  • The engine also builds as ring-3 programs (/bin/browser, /bin/js)
  • OldBrowser, which follows NetSurf's architecture and uses its libcss and libhubbub

Writing software on it

  • Code, an IDE with a project tree, tabs, syntax highlighting and a Run button
  • BoltCC, a compiler for a subset of C, C++ and C# with a C preprocessor. It normally targets a bytecode VM; cc -N compiles the integer subset to x86-64, and cc -c writes objects for the linker.
  • as (x86-64, NASM syntax), ld, ar and make
  • A source-level debugger (cc -g) with breakpoints, stepping, backtraces and locals by name
  • BoltPy, a small Python interpreter
  • vcs, a local version control system with branches and a real diff
  • pkg, a package manager with its own package and repository format, which installs from a directory or over HTTP
  • compile, which turns a C or Python file into a Windows .exe
  • A shell with variables, loops, functions, pipes, quoting, history, tab completion and man pages (SHELL.md), and edit, a nano-style editor
  • An SDK for building BoltOS programs on another machine (sdk/)

Accounts and security

  • Multiple accounts, PBKDF2-SHA256 password hashes, file owners and permission bits, sudo, a lock screen
  • vault, an encrypted folder (AES-256-GCM)

Updates

Every edition checks boltos.dev for a new version at startup and every six hours. Small updates install themselves; bigger ones wait in Settings → Updates. The new kernel is checked against its SHA-256 and written next to the old one before the switch, so a power cut mid-update doesn't break the install. bash release.sh desktop|tv|mini publishes one, and boltos.dev/updates shows the current versions.

BoltOS TV is the same kernel and drivers with a TV interface instead of the desktop. It boots straight into a full-screen film with the apps in a panel on the left. There's no login and no boot menu, and the USB image is a 37 MB download.

BoltOS TV

  • Live TV: six looping film channels with a channel banner and a guide
  • YouTube: search and full-screen playback, decoded on the TV itself (H.264 from Mini, plus an AAC-LC decoder written for the TV)
  • Netflix, Prime Video, Disney+ and HBO Max: played in Firefox on another computer on your network and streamed to the TV (webengine/)
  • Browser: a reader-view browser you drive with the remote
  • Ad Blocker: blocks DNS lookups to 293 ad, tracking and smart-TV telemetry networks, for every app on the set
  • Apple TV and HDMI 1 input screens, and Settings

Install steps and limits are in TV.md. The code is in tv/.

BoltOS Mini is a separate AArch64 kernel for the Orange Pi Zero3 (Allwinner H618, four Cortex-A53 cores, 1 GB). It's up about a quarter of a second after U-Boot hands over.

BoltOS Mini

It comes with nine apps:

  • Browser: Firefox, running in a Linux guest on cores 1-3. Mini starts at EL2 and keeps it, so it can be the hypervisor; the guest gets virtio disks, a screen, input and a network card that Mini provides. BoltOS's own engine is there as a fallback.
  • Code: an editor that runs Python, C and C++ on a spare core. The Python has big integers, floats, classes with inheritance, closures, exceptions, comprehensions, f-strings and a handful of standard modules. The C and C++ side is a typed front end with its own library.
  • Terminal, Monitor, Notes, Clock and Settings
  • Packages: installs extra apps from boltos.dev onto the SD card. The first is BoltOS Local AI, a chat with a small language model (Qwen or SmolLM, downloaded from Hugging Face) that runs on the Pi itself.
  • SoundCloud: search, For you, likes, history, a queue and your own playlists. It streams SoundCloud's HLS AAC (160 kbps), decoded on the Pi, out of the line out and HDMI at the same time.

Other bits:

  • The screen can be a Mac (the Pi shows up as a USB network adapter and macOS's Screen Sharing connects to its VNC server), an HDMI monitor, or a 3.5" SPI LCD.
  • USB and Bluetooth keyboards, mice and controllers work.
  • It can run unmodified aarch64 Linux programs (built against musl) on a spare core, with no Linux kernel involved.
  • Files live on the SD card's FAT32 partition, so a Mac sees the same folders.
  • mini/boot/ is the start of BoltBoot, Mini's own boot firmware to replace U-Boot. It brings up the clocks, power and DRAM, but doesn't boot the kernel yet.

Setup, wiring and the dev workflow are in MINI.md. The code is in mini/.

Some of the bigger gaps (the full list is in GUIDE.md and ROADMAP.md):

  • No driver for real Wi-Fi hardware on the desktop
  • No AML interpreter, so no battery readings and no hardware backlight control (brightness is a software dimmer)
  • After resuming from S3 only the boot CPU runs until the next reboot
  • One audio stream at a time
  • Text is Latin-1, so layouts that need UTF-8 aren't offered
  • USB devices are found at boot only, no hot-plug
  • BoltCC compiles a subset of C, and BoltOS can't build itself yet
  • Mini's sound is line out and HDMI only, no Bluetooth audio yet

The build needs clang, ld.lld, nasm and Python 3.

  • Windows: msys2, then pacman -S mingw-w64-ucrt-x86_64-clang mingw-w64-ucrt-x86_64-lld nasm
  • macOS or Linux: the micromamba environment in build/.tools/env described in TV.md
bash build.sh        # iso/os.img and iso/boltos.iso
bash run.sh          # boot in QEMU, serial output on stdio
bash run-uefi.sh     # the same with OVMF (UEFI)
bash build-tv.sh     # iso/boltostv.img
bash build-mini.sh   # build/mini/sdcard.img

There are also PowerShell scripts for VirtualBox images (rebuild-all.ps1, rebuild-vdi.ps1, build-and-run-vbox.bat), and bash mini/tools/run-qemu.sh runs Mini in QEMU on a Mac.

test/ has 69 test scripts, nearly all of which boot BoltOS in QEMU and check the serial output and the screen, plus host-side tests in test/host/ that compile kernel code natively and compare it with something independent:

  • the MP3 decoder against mpg123, and the TV's AAC decoder against ffmpeg
  • the assembler against NASM, and the linker and archiver against binutils
  • the WPA2 key schedule against the vectors in its own RFCs
  • every keyboard layout against what's printed on real keycaps
  • FAT32 against a disk that fails reads, tears sectors and loses power
python test/run_all.py          # everything
python test/run_all.py net fs   # tests whose name matches
python test/t_fuzz.py           # fuzz the network stack, browser and decoders
boot/        BIOS stage1/stage2 and the UEFI loader
kernel/      core kernel, desktop shell, apps, shell, compilers, browser engine
drivers/     storage, USB, network, audio, display, input
net/         network stack, TLS and crypto, SSH, 802.11
fs/          BoltFS, FAT32, EXT2
mm/          physical and virtual memory, heap, swap
include/     kernel headers
libc/        freestanding C library
user/        ring-3 programs and their runtime
oldbrowser/  the NetSurf-style browser
tv/          BoltOS TV
mini/        BoltOS Mini
sdk/         SDK for building programs on another machine
strike/ gb/ boltcraft/   BoltStrike, the Game Boy emulator, boltcraft
doom/        doomgeneric port
vendor/ netsurf/         vendored libraries
webengine/   the Firefox VM the TV and Mini can stream from
website/     boltos.dev
test/        QEMU and host tests, fuzzing

About 170,000 lines of C and assembly, not counting vendored code.

  • July 2026: first commit
  • September: boot menu, SSH, USB boot sticks, the regression suite
  • October: the glass desktop; BoltOS TV; BoltOS Mini on the Orange Pi, with its own browser, H.264 decoder and Local AI; updates over the air
  • November: Firefox on Mini and the TV, Linux programs on Mini, and the first steps of BoltBoot

Third-party code and assets

  • doomgeneric and the DOOM shareware WAD (doom/)
  • NetSurf's libcss, libhubbub, libparserutils, libwapcaplet and libdom (vendor/, netsurf/)
  • pl_mpeg for the TV's MPEG-1 films (vendor/pl_mpeg)
  • Inter, DejaVu Sans Mono and Montserrat fonts (assets/fonts/)
  • Lucide icons (assets/icons/)
  • The TV's films are cut from Pexels footage
  • Mini's Browser downloads Firefox, Debian and a Linux kernel the first time it opens
联系我们 contact @ memedata.com