Virtualization uses software to create a virtual version of a computing resource, such as a server, a disk or a network. Programs talk to the virtual version as if it were real hardware. That way one physical machine can run many independent machines at once. Every EC2 instance you launch is a virtual machine, so virtualization is the layer the whole cloud sits on.
The problem it solves#
Without virtualization, one physical server runs one operating system and its applications. Most applications use only a small part of the server's CPU, memory and disk. The rest sits idle, but you still pay for the power, cooling and space.
Virtualization fixes that waste. One physical server runs several virtual machines (VMs). Each VM has its own operating system and applications. The VMs share the hardware but cannot see each other.
Virtual machines and the hypervisor#
Two pieces make that sharing work: the VMs and the software that runs them. A virtual machine is a self-contained, isolated computer made of software. It has virtual CPUs, memory, disks and network cards, plus a guest operating system. The physical machine underneath is the host.
The hypervisor is the software that runs the VMs. It sits between the hardware and the VMs and does three jobs.
- Decoupling: it presents virtual hardware to each VM, so each VM runs as if it owns a machine. VMs on one host can run different operating systems.
- Resource allocation: it shares CPU, memory and storage among the VMs and adjusts the shares as workloads change.
- Overcommitment: it can hand out more virtual resources than the host has, betting that not every VM needs its full share at once.
All this translation could slow guest code down. Modern CPUs include hardware support for virtualization (Intel VT-x and AMD-V), which lets guest code run at close to native speed.
Type 1 vs Type 2 hypervisors#
Not every hypervisor sits directly on the hardware. Hypervisors come in two types, depending on what they run on.
| Type 1 (bare metal) | Type 2 (hosted) | |
|---|---|---|
| Runs on | The hardware directly | A normal host operating system |
| Performance | Better: no host OS in the way | Lower: every call passes through the host OS |
| Used for | Servers and data centers | Desktops and laptops |
| Examples | VMware ESXi, Microsoft Hyper-V, Xen, KVM | Oracle VirtualBox, VMware Workstation |
Cloud providers use Type 1 hypervisors. AWS runs current-generation EC2 instances on its Nitro system, whose hypervisor is based on KVM.
Key properties of VMs#
With the hypervisor in place, each VM gets four properties. Together they explain why VMs are so useful.
| Property | What it means | What it gives you |
|---|---|---|
| Partitioning | One host's resources are split among many VMs | Several operating systems on one server |
| Isolation | A crash or malware in one VM does not reach the others | Fault and security containment; per-VM resource limits |
| Encapsulation | A whole VM (OS, apps, data, state) is saved as a set of files | Copy, back up or move a VM like a file |
| Hardware independence | A VM runs on any host with the same hypervisor | Move or restart VMs on other hosts without driver issues |
Encapsulation and hardware independence together enable live migration: moving a running VM to another host with no visible downtime. Providers use this to service hardware without stopping your workload.
Server consolidation#
Partitioning is what makes the most common first use of virtualization possible. Server consolidation means moving workloads that ran on many lightly used physical servers onto fewer hosts as VMs. It is often the first project when a company adopts virtualization.
- Fewer servers to buy, power, cool and house.
- Higher use of each server's CPU and memory.
- Faster provisioning: a new VM takes minutes, a new server takes weeks.
- Easier disaster recovery, because VMs are files you can copy to another site.
Virtualization is not cloud computing#
Since clouds run on VMs, it's easy to treat the two words as one. They are related but not the same.
- Virtualization is a technology. It creates virtual resources on physical hardware.
- Cloud computing is a way to deliver resources: on demand, self-service, metered, over the network.
Clouds use virtualization underneath, then add automation, self-service APIs, billing and elastic scaling on top. A company can virtualize its own data center without using any cloud. Virtualizing first is still a common step toward the cloud, because the workloads are already packaged as VMs. The why cloud note lists the characteristics that make an environment a cloud.
VMs vs containers#
VMs aren't the only way to isolate workloads. A container packages an application and its dependencies, but not a full operating system. Containers on one host share the host's kernel. On Linux, the kernel isolates them with namespaces (what a process can see) and cgroups (how much it can use).
| Virtual machine | Container | |
|---|---|---|
| Isolation unit | Whole machine, own kernel | Process, shared host kernel |
| Isolation strength | Stronger: hypervisor boundary | Weaker: one kernel bug can affect all |
| Image size | Gigabytes (includes a full OS) | Often megabytes |
| Start time | Tens of seconds to minutes | Seconds or less |
| Guest OS | Any OS the hypervisor supports | Must match the host kernel (Linux on Linux) |
In the cloud, the two usually work together. Containers run inside VMs: the VM gives strong isolation between customers, and containers give fast, dense packing of apps inside one customer's VMs. Some services blur the line with microVMs, small VMs that start almost as fast as containers. AWS Lambda runs on Firecracker microVMs.
Trade-offs and pitfalls#
Everything so far has been a benefit, but virtualization has costs too.
- Overhead: the hypervisor uses some CPU and memory, though hardware support keeps it small.
- Noisy neighbors: VMs on one host compete for shared caches, disk and network, which can cause variable performance.
- Overcommitment risk: if every VM needs its full share at once, they all slow down.
- VM sprawl: VMs are cheap to create, so unused ones pile up and cost money.
Key takeaways#
- Virtualization lets one physical host run many isolated virtual machines.
- The hypervisor decouples VMs from hardware and shares resources among them.
- Type 1 hypervisors run on bare metal and power the cloud. Type 2 run on a desktop OS.
- Partitioning, isolation, encapsulation and hardware independence make VMs easy to pack, move and recover.
- Virtualization is a technology; cloud computing is an on-demand delivery model built on it.
- Containers share the host kernel, so they are lighter but less isolated than VMs. In the cloud they usually run inside VMs.