Leanpub Header

Skip to main content

Building a Hypervisor in Rust

From First Principles to a Full Virtualization Platform

This book is 100% completeLast updated on 2026-07-13

Build a complete x86_64 hardware-assisted hypervisor in Rust from the ground up. Through real, compilable code and clear explanations, you'll implement every major subsystem, from CPU and memory virtualization to device emulation, VirtIO, and multi-vCPU scheduling, gaining a practical understanding of modern virtualization.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
About

About

About the Book

This book teaches you how to implement a complete x86_64 hardware-assisted hypervisor entirely in Rust. Starting from an empty project, you will build every component: CPU virtualization using Intel VT-x (with AMD-V parallels), extended page tables for memory isolation, VM exit handling, interrupt and APIC virtualization, device emulation, VirtIO paravirtualized devices for storage and networking, ACPI table generation, guest firmware loading, and multi-vCPU scheduling. Every concept is grounded in working, compilable Rust code with line-by-line explanations. No placeholders, no pseudocode, no hand-waving. If you have systems programming experience and want to understand how virtualization really works at the hardware level, this book will take you there.

Bundles

Bundles that include this book

Author

About the Author

Steve T. Publications

Steve T. Publications is a specialized book publishing company dedicated to delivering high-quality technical resources for IT professionals, students, educators, and technology enthusiasts. Our mission is to make complex technology concepts accessible through well-structured, practical, and industry-relevant publications.

We focus on publishing books across a wide range of information technology disciplines, including software development, cloud computing, cybersecurity, artificial intelligence, data science, networking, DevOps, databases, and enterprise technologies. Every publication is designed to bridge the gap between theory and real-world application, helping readers build the skills needed to succeed in today's rapidly evolving digital landscape.

At Steve T. Publications, we collaborate with experienced industry experts, educators, and technology professionals to produce accurate, up-to-date, and engaging content. We are committed to maintaining the highest editorial standards while empowering learners and professionals with trusted technical knowledge.

Whether you're beginning your IT journey, preparing for professional certifications, or advancing your expertise in emerging technologies, Steve T. Publications is your trusted source for authoritative and practical technical books.

Contents

Table of Contents

From First Principles to a Full Virtualization Platform

Introduction: The Virtual Machine

  1. Why Rust?
  2. What This Book Covers
  3. How to Use This Book
  4. What This Book Is Not

Chapter 1: Project Foundation — Bare-Metal Rust on x86_64

  1. Setting Up the Cross-Compilation Toolchain
  2. Memory Allocator for no_std
  3. The Linker Script
  4. The Bootloader Handoff — Multiboot2 Entry
  5. Entering Long Mode from Real Mode
  6. The Core Kernel Entry Point
  7. Memory Layout and Early Allocator
  8. Early Console — Serial Port Output

Chapter 2: Understanding x86_64 Virtualization Hardware

  1. The Root/Non-Root Execution Mode Model
  2. CPUID Detection and Feature Enumeration
  3. Intel VT-x Architecture — VMXON, VMCS, and VM Entry/Exit
  4. AMD-V Architecture — SVM and the VMCB
  5. The Virtualization Instruction Set
  6. Hypervisor Initialization

Chapter 3: Guest Memory Management — Extended Page Tables

  1. The Two-Level Translation Problem
  2. EPT Page Table Structure
  3. AMD NPT — The Parallel Path
  4. Building Guest RAM Mappings

Chapter 4: VMCS Configuration and Guest CPU State

  1. VMCS Layout and Field Encoding
  2. Guest-State Area Configuration
  3. Host-State Area Configuration
  4. VMCS Validation and Error Codes

Chapter 5: Virtual CPU Lifecycle — Launch, Resume, and Exits

  1. The vCPU Data Structure
  2. VMLAUNCH vs VMRESUME — The First Entry Problem
  3. VM Entry Failures and Recovery

Chapter 6: Interrupts, Exceptions, and the APIC

  1. The x86 Interrupt Model Recap
  2. Virtualizing the IDT — Exception Bitmap Control
  3. Local APIC Virtualization
  4. I/O APIC and Interrupt Routing
  5. Event Injection — Delivering Interrupts to Guests

Chapter 7: I/O Virtualization — MMIO, PIO, and PCI Passthrough

  1. Memory-Mapped I/O via EPT Intercepts
  2. Port I/O Interception — IN/OUT Instructions
  3. PCI Configuration Space Access
  4. MSI and MSI-X Virtualization
  5. Device Passthrough Fundamentals

Chapter 8: Virtual Devices — Serial, RTC, and PIT Emulation

  1. The VirtIO Framework — Paravirtualized Device Standard
  2. Serial Port Emulation (COM1)
  3. RTC and PIT Emulation
  4. HPET — High Precision Event Timer
  5. ACPI Tables Construction

Chapter 9: Storage and Block Device Virtualization

  1. VirtIO Block Device Specification
  2. Building the VirtIO Block Backend
  3. VirtIO Console — Character Device Virtualization
  4. Raw Disk Access and Backing Store Management

Chapter 10: Networking Virtualization

  1. VirtIO Net Device Specification
  2. Building the VirtIO Net Backend
  3. TAP Device Integration on Linux
  4. MAC Address and VLAN Handling
  5. Network Performance Considerations

Chapter 11: Guest Boot — BIOS/UEFI Firmware Loading

  1. BIOS vs UEFI Boot Paths
  2. Loading SeaBIOS — The Simple Path
  3. Loading OVMF — UEFI Firmware
  4. Guest Kernel Direct Boot (no firmware)
  5. Debugging the First Guest Boot

Chapter 12: Multi-vCPU Systems and Scheduling

  1. vCPU Pinning and Host Thread Mapping
  2. Inter-Processor Interrupts (IPIs)
  3. vCPU Scheduling Strategies
  4. SMP Boot Sequence — Waking APs
  5. Cross-vCPU State and Communication

Chapter 13: Performance, Debugging, and Security

  1. Profiling VM Exit Overhead
  2. TSC Scaling and Clock Virtualization
  3. GDB Stub and Hypervisor Debugging
  4. Security Hardening — Isolation and Sandboxing
  5. Error Handling and Recovery Patterns
  6. Benchmarking Methodology
  7. Troubleshooting Common Failures
  8. Cross-Platform Considerations
  9. Production Deployment Checklist

Conclusion: What We Built and Where to Go Next

References

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