Black Friday Deals For Authors Are On Now!

Leanpub Header

Skip to main content

Implementing MicroVMs with Rust

A Deep Dive into Virtualization, Linux KVM and Low-Level Systems Engineering

Implementing MicroVMs with Rust
This book is 100% completeLast updated on 2026-11-27

Go beyond treating virtualization as a black box. Build a working MicroVM from scratch using Rust and Linux KVM, exploring everything from memory management and device emulation to VM exits and interrupt handling. A hands-on deep dive into the inner workings of hypervisors and the low-level engineering that makes modern cloud infrastructure possible.

Minimum price

$35.00

$45.00

You pay

Author earns

$

Also available for 2 book credits with a Reader Membership

PDF
EPUB
WEB
APP
414
Pages
About

About

About the Book

You are about to build a virtual machine monitor. Not a wrapper around someone else's, not a configuration of QEMU, but a working MicroVM from the KVM API upward, written in Rust, with every device, every memory region and every interrupt path designed and implemented by you.

This book exists because virtualization is one of the most important and most misunderstood technologies in modern computing. Every time you deploy a serverless function, spin up a container, or launch a cloud instance, a hypervisor is doing the heavy lifting. Yet most engineers treat it as a black box: you pass it a kernel image and some memory and out comes a running operating system. How does it actually work? What happens when the guest executes a port I/O instruction? How does the hypervisor keep a malicious guest from reading another tenant's memory? What does "MicroVM" even mean, beyond a marketing term?

By the end of this book, you will know the answers to these questions because you will have built the system yourself. You will have traced the path from an Intel VT-x VM exit, through the Linux KVM kernel module, into your Rust userspace code and back again. You will understand why every design decision in a virtual machine monitor is a trade-off between security, performance and complexity.

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience spanning software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. His work focuses on understanding complex systems, uncovering security weaknesses and developing practical solutions that make technology more secure, reliable and effective.

Through Steve Publications, he collaborates with experienced researchers, engineers and industry experts to create practical, technically rigorous books on various topics not limited to self-improvement, software development, cybersecurity, cloud computing, DevOps, artificial intelligence and enterprise technologies. His mission is to make complex technical subjects accessible through clear explanations, real-world examples and hands-on exercises that help IT professionals, students and technology enthusiasts build valuable, practical skills.

Steve Publications embraces AI as a supporting tool for translation, proofreading and editorial refinement, not as a substitute for original research, technical expertise, or hands-on experience. Some contributors choose to publish under pseudonyms to protect their privacy or maintain professional boundaries.

Behind every book is a commitment to technical accuracy, practical relevance and continuous improvement. Our publications are written, reviewed and maintained by experienced professionals, with support from a private community of more than 420 engineers and researchers. Rather than prioritizing volume or mass-produced AI-generated content, we focus on delivering reliable, useful resources that readers can apply in real-world environments.

We also welcome experienced professionals who want to share their knowledge by writing or reviewing books, particularly in specialized and emerging technology fields. If you have expertise to contribute, we invite you to get in touch and explore opportunities to collaborate.

Our commitment is simple: To deliver books that respect our readers' time, support their professional growth and provide lasting practical value. If a book does not meet your expectations, Leanpub offers a 60-day money-back guarantee.

Contents

Table of Contents

A Deep Dive into Virtualization, Linux KVM and Low-Level Systems Engineering

Preface

  1. Who This Book Is For
  2. How This Book Is Organized
  3. The Central Thesis
  4. Conventions
  5. Building the Project

Part I: Foundations of Virtualization

Chapter 1: The Case for MicroVMs

  1. From Bare Metal to Serverless: The Demand for Isolation
  2. Containers, VMs, Unikernels and the MicroVM Sweet Spot
  3. What Makes a MicroVM a MicroVM
  4. Historical Context: Xen, KVM and the Rise of Firecracker
  5. The Promise of This Book

Chapter 2: Privilege Levels and CPU Virtualization

  1. The Problem: Protecting the Hypervisor
  2. x86 Privilege Levels and Ring 0
  3. Intel VT-x: VMX Root and Non-Root Operation
  4. AMD-V: SVM and Its Differences from VMX
  5. The VMCS and VMCB: Per-Virtual-CPU State
  6. VM Entry and VM Exit: The Fundamental Primitive
  7. Summary

Chapter 3: Memory Virtualization

  1. The Problem: Two Operating Systems, One Memory
  2. Guest Virtual to Guest Physical: The Guest’s Own MMU
  3. EPT and NPT: Second-Level Address Translation
  4. Memory Regions and KVM Memory Slots
  5. Huge Pages and Memory Performance
  6. Copy-on-Write and Memory Overcommit
  7. Summary

Chapter 4: I/O Virtualization and virtio

  1. The Problem: Devices in a Virtual Machine
  2. Port I/O and Memory-Mapped I/O
  3. Device Emulation: Why QEMU Is Slow
  4. Paravirtualization and the virtio Philosophy
  5. The virtio Feature Bit Negotiation Protocol
  6. virtio Ranges, Device Types and Modern virtio
  7. Summary

Chapter 5: Interrupts, Timers and the APIC

  1. The Problem: Delivering Events to the Guest
  2. The x86 Interrupt Architecture: PIC to APIC
  3. Virtualizing Interrupts: Posted Interrupts and Virtual Wire Mode
  4. The KVM PIC and IOAPIC Emulation
  5. Timers: TSC, PIT, HPET and the virtio Clock
  6. Interrupt Routing and MSI/MSI-X
  7. Summary

Part II: Linux KVM in Depth

Chapter 6: The KVM Architecture

  1. KVM as a Linux Kernel Module
  2. The /dev/kvm Interface and File Descriptor Model
  3. Kernel vs Userspace Responsibilities
  4. KVM Architecture on x86: VMX and SVM Modules
  5. Kernel Versions, Capabilities and Feature Detection
  6. Summary

Chapter 7: The KVM Userspace API

  1. The KVM ioctl Taxonomy: /dev/kvm, VM, vCPU, Device
  2. Creating VMs and vCPUs: KVM_CREATE_VM, KVM_CREATE_VCPU
  3. Register Access: KVM_GET_REGS, KVM_GET_SREGS, KVM_GET_LAPIC
  4. Interrupt Injection: KVM_IRQFD, KVM_IRQ_LINE
  5. Signal Handling, Scheduling and vCPU Threads
  6. Summary

Chapter 8: KVM Memory Management and MMU

  1. Memory Slots and KVM_SET_USER_MEMORY_REGION
  2. Memory Mapping with mmap and KVM
  3. The KVM Shadow Page Table (EPT/NPT) Management
  4. Huge Pages in KVM: 2MB and 1GB Pages
  5. Memory Hotplug and Dynamic Memory
  6. Summary

Part III: Building the MicroVM in Rust

Chapter 9: Project Architecture and Rust for Systems

  1. Project Layout and Cargo Configuration
  2. Rust for Systems Programming: Ownership, Lifetimes and Unsafe
  3. Error Handling Strategies in Systems Code
  4. The VMM Module Map

Chapter 10: Creating the Virtual Machine

  1. Opening /dev/kvm and Checking Capabilities
  2. Allocating Guest Memory with mmap
  3. Registering Memory Slots with KVM
  4. Verifying the VM State
  5. Summary

Chapter 11: Creating and Running vCPUs

  1. Creating vCPU Threads and File Descriptors
  2. Initializing CPU State: GPRs, Segment Registers, MSRs
  3. The vCPU Run Loop and KVM_RUN
  4. Handling VM Exits in Rust
  5. Multi-vCPU Synchronization and Shutdown
  6. Summary

Chapter 12: Booting a Linux Kernel

  1. The Linux Kernel Boot Protocol
  2. Loading the Kernel into Guest Memory
  3. Entering the Kernel: Long-Mode CPU State
  4. First Boot: Getting a Kernel to Run
  5. Summary

Chapter 13: The Device Framework and Serial Console

  1. The VMM Device Trait and Abstraction
  2. Port I/O Handling: The KVM_EXIT_IO Path
  3. Implementing a 16550 UART for Console Output
  4. Memory-Mapped I/O Regions in Rust
  5. Device Registration and Address Spaces
  6. Summary

Chapter 14: Virtio Foundations

  1. The virtio Transport Model
  2. Descriptor Rings, Available Rings and Used Rings
  3. Feature Negotiation in Practice
  4. Implementing VirtQueue in Rust

Chapter 15: Virtio Block Device

  1. The virtio-blk Configuration and Headers
  2. Request Types: Read, Write, Flush, GetID
  3. The Block Device Backend: File I/O
  4. Integrating Virtio-Blk with the Kernel Command Line
  5. Performance Considerations and AIO
  6. Summary

Chapter 16: Virtio Networking

  1. The virtio-net Configuration and Packet Headers
  2. Network Backends: TAP Devices and Network Namespaces
  3. Packet Flow: Guest to Host and Back
  4. Multi-Queue Networking and RSS
  5. Multi-Queue Networking and RSS
  6. Network Performance and Buffering
  7. Wiring the Net Device into the VMM
  8. Summary

Chapter 17: Interrupt Delivery and the Event Loop

  1. Interrupts in a Virtual Machine
  2. KVM_IRQFD and EventFD-Based Interrupts
  3. Building the VMM Event Loop with epoll
  4. Multiplexing vCPU, Device and Control Events
  5. The Virtio Interrupt Signaling Path
  6. Timer and Clock Virtualization
  7. Summary

Part IV: Advanced Engineering

Chapter 18: Concurrency, Async I/O and Performance

  1. Concurrency in Virtual Machine Monitors
  2. Async I/O: epoll vs io_uring
  3. vCPU Affinity, Pinning and NUMA
  4. Profiling and Performance Benchmarking
  5. Summary

Chapter 19: Memory Management Deep Dive

  1. Guest Memory Layout and the Physical Address Space
  2. Huge Pages for the Guest: 2MB and 1GB
  3. Copy-on-Write Cloning for Fast Startup
  4. Memory Hotplug and Dynamic Sizing
  5. Ballooning and Memory Reclaim
  6. Summary

Chapter 20: Security Engineering for MicroVMs

  1. The MicroVM Threat Model: Untrusted Guests
  2. Attack Surfaces: KVM, Devices, Memory, vCPU
  3. Process Sandboxing: Namespaces, Capabilities, chroot
  4. seccomp-BPF Filters: Restricting System Calls
  5. cgroups and Resource Isolation
  6. Guest Escape Risks and Mitigations
  7. Summary

Part V: Production and Landscape

Chapter 21: Production VMM Architecture

  1. From Prototype to Production
  2. API Server and Instance Lifecycle Management
  3. Configuration, Validation and Defaults
  4. Structured Logging, Metrics and Tracing
  5. Graceful Shutdown and Crash Recovery
  6. Summary

Chapter 22: Snapshots, Checkpoints and Restore

  1. What Makes a VM Snapshot
  2. Device State Serialization in Rust
  3. Memory Snapshotting and CoW
  4. Restore: Reconstructing a Running VM
  5. Limitations and Open Problems
  6. Summary

Chapter 23: The VMM Landscape: Firecracker, Cloud Hypervisor, crosvm and QEMU

  1. Why Study Other VMMs
  2. Firecracker: The Security-Focused MicroVM
  3. Cloud Hypervisor: The Full-Featured MicroVM
  4. crosvm: The Chrome OS VMM
  5. QEMU: The General-Purpose Emulator
  6. Comparative Analysis
  7. Lessons Learned from the Landscape
  8. Summary

Chapter 24: Future Directions and Conclusion

  1. Emerging Technologies in Virtualization
  2. Conclusion: The Art and Science of Building a MicroVM
  3. Final Thoughts

References

  1. Official Documentation and Specifications
  2. Research Papers and Technical Articles
  3. Source Code Repositories
  4. Hardware Manuals and Datasheets
  5. Online Resources

Appendix A: Complete Project Structure

  1. Cargo.toml

Appendix B: KVM ioctl Quick Reference

Appendix C: Boot Parameters Reference

  1. setup_header (at offset 0x1F1 in the bzImage header)
  2. screen_info (at offset 0 in boot_params)
  3. e820_mem_map (setup_data, type 1)

Appendix D: virtio Register Map

  1. virtio-blk Configuration
  2. virtio-net Configuration

Appendix E: Glossary

Appendix F: Index

  1. A
  2. B
  3. C
  4. D
  5. E
  6. F
  7. G
  8. H
  9. I
  10. K
  11. L
  12. M
  13. N
  14. P
  15. Q
  16. R
  17. S
  18. T
  19. U
  20. V
  21. W
  22. X
  23. Y
  24. Z

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.)

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