← Back to writing
5 min readTechnology

So, How Does Virtualization Actually Work?

You're using virtualization all the time, probably without even realizing it. Firing up a Docker container, spinning up an AWS EC2 instance, or running Windows on a Mac? That's all virtualization. It's the magic behind the cloud that turns one computer into many, and the bedrock of stuff like Kubernetes.

If you're a developer, you use this daily but probably don't think about it much. How can one CPU fake being several? How do a bunch of operating systems, each thinking it owns the hardware, share everything without fighting?


What Virtualization Really Is

Basically, virtualization is all about faking it: making one physical thing act like a bunch of virtual ones.

The most common type is hardware virtualization, which gives us virtual machines. A VM gets its own virtual CPU, memory, and disk, and runs its own entire operating system. The software that pulls this off is called a hypervisor, or a Virtual Machine Monitor. As a quick etymology fact, "supervisor" comes from the Latin supervidere, meaning “to oversee,” and it’s the old-school name for kernel. "Hypervisor" literally means “over the supervisor,” since it's software that sits above the OS kernels to manage all the different VMs.

There are two main types of hypervisors. A Type 1, or "bare metal," hypervisor runs right on the hardware itself, like ESXi or Hyper-V. In contrast, a Type 2, or "hosted," hypervisor runs as an app on top of another OS, like VirtualBox or Parallels.


How CPU Virtualization Works

Virtualizing the CPU is the trickiest part, 'cause every OS is a control freak and expects to be the boss. CPUs manage this with privilege rings, which are basically security clearance levels. Ring 0 is for the kernel, giving it total control, while Ring 3 is for regular apps with limited access.

Normally, only one OS gets Ring 0. But with virtualization, you have multiple guest OSes all fighting for that top spot. The old, slow way to handle this was for the hypervisor to take Ring 0 and force the guest OS into a lower ring. Anytime the guest tried to do something important, it would "trap," and the hypervisor would have to step in and emulate it. This worked, but it was slow.

The modern, fast way came when Intel and AMD added a new mode to their CPUs. Now, guests think they're in Ring 0, but the hypervisor is secretly running the show from a new "root mode." The CPU hardware handles this switch super fast.


How Memory Virtualization Works

Every OS uses page tables to keep track of its memory. When you have a bunch of VMs, you can't just let them all grab at the same physical RAM, or you'd have chaos. The hypervisor has to manage this. The old way involved the hypervisor keeping "shadow page tables" to translate the guest's memory addresses to the real physical memory. Again, this worked, but it was slow. The modern way is much better, as CPUs now have a second layer of address translation built right into the hardware. This means the CPU handles the translation directly, which is way faster.


Containers vs. VMs (and Paravirtualization)

VMs are powerful, but they're heavy since each one has a full OS. Containers are much lighter. I love this analogy: VMs are like separate houses, each with its own plumbing and foundation. Containers, on the other hand, are like apartments in one building. They're separate units, but they all share the building's core plumbing, which is the host OS kernel.

This is why containers can start up in milliseconds while VMs take minutes, and it's why they're the standard for things like CI/CD and microservices.

Then there's also paravirtualization, where the guest OS knows it's being virtualized and cooperates with the hypervisor. Today, this is mostly just for super-fast drivers to avoid slow hardware emulation.


Where You Actually See This Stuff

This isn't just some clever theory; it's what runs today's infrastructure. You see it in live migration, where a running VM is moved from one server to another without anyone noticing a hiccup. It's also behind virtual networks and storage, where things like AWS VPCs and cloud volumes are just virtualization layers on top of physical hardware. You can even get high-performance I/O with SR-IOV, which lets you slice up a single physical network card or GPU and give a piece directly to different VMs for max speed.


So, Why Does This Matter?

Virtualization originally started as a way to squeeze more value out of pricey servers. Now, it's the foundation for the cloud, containers, and all of DevOps.

It's more than just running Windows on your Mac; it's about breaking the link between software and the hardware it runs on. This gives us systems that are way more efficient, scalable, and flexible. The whole "computers inside computers" thing might sound like a gimmick, but it's literally how modern computing gets done.