Virtual machines and hypervisors
Virtual machines and hypervisors
Recorded by Dr. Krithika L.B. Slot m5-hypervisors
Why we virtualise, how a host, hypervisor and guests fit together, type 0/1/2 hypervisors, trap-and-emulate, binary translation and hardware support, full versus para-virtualization, and live migration.
By the end of this session you should be able to:
The idea goes back to IBM's VM/370 (1972): abstract the hardware of a single computer into several execution environments, each believing it has its own machine. Today it is the foundation of cloud computing.
Many lightly loaded servers become VMs on one physical host — fewer machines, less power and space.
Each guest is protected from the others; a virus in one VM cannot reach another.
Run several OSes (Windows, Linux versions) on one laptop; snapshot and roll back.
Keep old applications running on their old OS on new hardware.
Move a running guest to another host for maintenance or load balancing, with no downtime.
IaaS providers (AWS EC2, Azure, GCP) rent VMs on demand.
Three components: the host (underlying hardware), the virtual machine manager (VMM) or hypervisor (creates and runs VMs, providing an interface identical to the host), and the guests (each usually a full operating system).
Non-virtual machine
Virtual machines
Hardware-based — implemented in firmware; the hardware is partitioned among guests (IBM LPARs, Oracle LDOMs). Each guest gets dedicated resources.
Bare-metal — the hypervisor is a small OS-like layer running directly on the hardware, with guests on top. Very efficient; used in data centres.
Examples: VMware ESXi, Citrix XenServer, Microsoft Hyper-V, KVM (turns Linux itself into a type 1 hypervisor).
Hosted — the hypervisor is an application on a normal host OS. Easy to install on a laptop; lower performance because it relies on the host OS.
Examples: Oracle VirtualBox, VMware Workstation, Parallels Desktop.
The guest kernel believes it runs in kernel mode, but it actually runs in user mode (Session 1.3) — otherwise it could take over the real machine. So what happens when it executes a privileged instruction?
A privileged instruction in user mode traps to the VMM, which emulates its effect on the guest's virtual state and returns. Works only if every sensitive instruction traps — not true of classic x86.
VMware's technique for x86: guest kernel code is inspected and the problematic instructions are rewritten into safe equivalent sequences on the fly (with caching). Unmodified guests run at good speed.
Intel VT-x and AMD-V add a new CPU mode for the VMM (host vs guest mode) and nested page tables (EPT/NPT), so guests run natively and the hardware traps only what is needed. Used by every modern hypervisor.
| Full virtualization | Para-virtualization | |
|---|---|---|
| Guest OS | Unmodified — it does not know it is virtualised | Modified — it knows and cooperates |
| Privileged operations | Trap-and-emulate, binary translation or hardware assist | Replaced by explicit hypercalls to the hypervisor |
| Performance | Good (excellent with VT-x/AMD-V) | Very good — fewer traps, simpler hypervisor |
| Compatibility | Any OS (even Windows) runs as is | Needs OS source changes (or paravirtual drivers) |
| Examples | VMware ESXi/Workstation, VirtualBox, KVM, Hyper-V | Xen (original), virtio drivers in KVM guests |
Today the line has blurred: hardware-assisted full virtualization runs the CPU, while paravirtual drivers (virtio) make disk and network I/O fast. Related ideas: emulation (running code for a different CPU, e.g. QEMU emulating ARM on x86 — slow) and application containment, the topic of the next session.
The source VMM connects to the target and gets permission to send a guest.
The target creates a new guest; the source sends all read-only pages, then read–write pages — while the guest keeps running.
Pages the guest modifies are re-sent, repeatedly, until the set of dirty pages is very small.
The source freezes the guest, sends the CPU state and the last dirty pages, and the target starts the guest. Network connections continue — downtime is milliseconds.
Virtual machines and hypervisors
Recorded by Dr. Krithika L.B. Slot m5-hypervisors
Work through these in order after the lecture — each one expands a part of the notes with diagrams, hover notes and a quick check.
Answer each question in your own words first, then reveal the model answer.
Revealed 0Type 2 — it runs as an application on the host OS.
It could then control the real hardware and the other guests; the VMM must keep control, so the guest runs in user (or guest) mode.
An explicit call from a para-virtualized guest kernel to the hypervisor, replacing a privileged instruction.
Some sensitive instructions (e.g. POPF) behave differently in user mode without trapping, so the VMM never got control. Binary translation or VT-x/AMD-V fixed this.
A VM virtualises the whole machine, including a full guest kernel. What if applications only needed isolation from each other on one shared kernel? That is OS-level virtualization: containers.
Continue to 5.6 — Containers and Docker →