Leanpub Header

Skip to main content

Build Your Own Operating System

A working x86-64 kernel in 90 pages — bootloader, scheduler, FAT12 driver, window manager — all the way to a real PC.

Minimum price

$4.99

$14.99

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
About

About

About the Book

A small, hands-on book on writing an operating system that boots on an actual computer.

Most OS-development resources either send you to a comprehensive academic textbook (OSTEP) or hand you a tutorial that works perfectly in QEMU and silently fails on real hardware. Build Your Own Operating System does neither.

It is a brisk, opinionated companion to NexusOS, a ~3,000-line x86-64 reference kernel. The kernel boots from a 512-byte BIOS bootloader you can read in one sitting, runs in 64-bit long mode with its own GDT and four-level page tables, manages physical and virtual memory through a real PMM / VMM / heap stack, preempts tasks at 100 Hz with mutex, semaphore, and condition-variable primitives, talks to a disk over PIO ATA and reads a FAT12 filesystem, composites a graphical desktop with a draggable terminal window, and boots on actual hardware, not just in the emulator.

Each chapter introduces one subsystem in plain language, inlines the actual code that implements it (line numbers match the source tree), and ends with exercises that ask you to modify the reference kernel rather than retype 3,000 lines from a blank file.

What makes this book different from the free alternatives

Real-hardware war stories. When NexusOS first booted on an ASUS desktop, the BIOS E820 call returned a memory map with no usable RAM. Then the ATA driver hung forever on a SATA-only machine, because the legacy IDE port reads 0xFF, which has the busy bit set. Then VBE hung inside the BIOS call, and you cannot time-out a BIOS call that never returns. Every chapter has the specific bug, the specific fix, and the defensive code that survived. Chapter 12 is the most honest chapter in the book.

A working kernel, not pseudocode. xv6 is RISC-V (or older x86) and academic. Phil Opp's series is excellent, but it's in Rust. NexusOS is C and assembly, x86-64, and you can make rungui today and modify it tonight.

What you'll need

Comfort with C and a little assembly. WSL on Windows, or any Linux or macOS shell. No prior bare-metal experience. About 90 pages of focused reading, plus as much time at the keyboard as you choose to give it.

What you'll have at the end

By Chapter 11, a graphical desktop running in an emulator. By Chapter 12, the same OS running on a real PC, with a panic dump you wrote yourself arriving over a serial cable when something goes wrong. By Chapter 13, a clear picture of what to build next — user mode, syscalls, ELF, SMP, networking, porting — and how to start.

Free sample

Includes the Preface and Chapters 1–2: enough to read the philosophy of the book, set up your toolchain, and write the smallest real OS — a 512-byte boot sector that prints OK on a virtual machine.

Author

About the Author

Noah Parsons

Noah Parsons writes systems software, computational physics tooling, and applied policy research from Newcastle, Wyoming. He came to bare-metal programming the way most people do, by getting curious about what actually happens between the power button and the cursor, then refusing to put the question down, and to physics by way of frustration with proprietary commercial tools and services.

NexusOS, the x86-64 reference kernel this book is built around, is the larger of his two flagship technical projects. The other is MechanicsDSL, a multi-target physics compiler built on SymPy that translates a LaTeX-inspired notation for mechanical and field-theoretic systems into executable simulations across a dozen code-generation backends: C++, CUDA, OpenMP, Rust, Julia, Fortran, MATLAB, JavaScript, WebAssembly, Arduino, Unity, and Modelica. MechanicsDSL is published as six PyPI packages (mechanicsdsl-core, -datasets, -notebooks, -unity, -ros2, and -embedded), is MIT-licensed under Zenodo DOI 10.5281/zenodo.17771040, and has been downloaded roughly 17,000 times across 70 countries at the time of writing, with institutional mirror adoption on bandersnatch, Nexus, and devpi. The two projects share a temperament more than a code base, both are attempts to take something that is usually presented as forbidding (a physics derivation, a kernel) and make it small enough to hold in one head.

On the research side, he is at work on an analytical model of energy and information transport in boundary-driven nonequilibrium quantum spin chains, in preparation toward submission. The piece sits in the same neighborhood as condensed-matter transport theory but stays close to closed-form results, which is the kind of physics he most enjoys: tractable enough to argue with on paper, rich enough to keep surprising you.

His applied policy work has appeared in the peer-reviewed Applied Journal of Economics, Law and Governance (a 32-page paper on grid modernization, Volume 1, Issue 2) and in shorter Zenodo-archived briefs on Medicare drug-price negotiation, the October 2025 federal government shutdown, and U.S. industrial competitiveness. In 2025 he served as Director of Civic Innovation at the American Forge Institute, since dissolved. Recognition for the broader body of work includes First Place in Engineering and Mathematics at the High Plains Regional Science and Engineering Fair, the Citadel Securities Innovation Prize, the Naval Science Award from the Office of Naval Research, and an Air Force Certificate of Achievement from AFRL, along with an invitation to the NASA STEM Engagement Mars Mission program.

Find him at github.com/GuiloScion and ORCID 0009-0000-7224-6040. NexusOS, MechanicsDSL, and the source for every listing in this book are MIT-licensed; issues, pull requests, and inquiries are welcome.

Contents

Table of Contents

Table of Contents

Front matter
  • Preface
Chapters
  1. Introduction: what is an OS, and what will we build?
  2. Your toolchain and first boot
  3. How a PC boots: BIOS, real mode, and the bootloader
  4. From 16-bit to 64-bit: protected mode, paging, and long mode
  5. Your first C kernel: freestanding code and output
  6. Interrupts: the IDT, exceptions, the PIC, the timer, and the keyboard
  7. Memory management: physical frames, paging, and the heap
  8. Multitasking: a scheduler and synchronization
  9. Storage: talking to a disk and reading a filesystem
  10. Graphics: the framebuffer, fonts, and a console
  11. A window manager: the mouse, a compositor, and windows
  12. Running on real hardware (and how to debug)
  13. What to build next
Back matter
  • Appendix A. Glossary
  • Appendix B. Resources and further reading
  • Appendix C. Full source listings
  • About the author

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub