A topic in the Open Knowledge Graph — a free, open map of 15,495 topics and the order to learn them in.
A virtual machine (VM) is a software-created computer that runs a complete guest operating system as if it had real hardware to itself. A hypervisor, also called a virtual machine monitor (VMM), creates the VMs, divides the real CPU, memory and devices among them, and keeps them isolated from one another. Type 1 hypervisors run directly on the hardware, while Type 2 hypervisors run as applications on a host operating system. Virtualization is how cloud providers run many customers' systems safely on shared servers.
Install a Type 2 hypervisor and boot a second operating system in a window, then look at the host's process list to see the whole VM appear as ordinary processes. Connect the mechanism to what students know about user mode, kernel mode and traps: walk through what happens when the guest kernel executes a privileged instruction. Finish by contrasting a VM with a container on the same machine, focusing on which kernel each one uses.
You know that an operating system runs user programs in a restricted CPU mode and keeps kernel mode for itself. When a program needs something privileged, it makes a system call or causes a trap, and the kernel takes over. Virtualization applies the same trick one level lower. The hypervisor takes the most privileged position on the machine, and whole operating systems run beneath it as guests.
Each virtual machine sees a virtual CPU, virtual memory and virtual devices such as a disk and a network card. The guest OS boots, schedules processes and manages memory as usual. Most of its instructions, such as additions, loads and branches, run directly on the real CPU at full speed. The hypervisor steps in only when the guest tries something that would affect the real machine, such as changing page tables, disabling interrupts or talking to hardware.
The classic mechanism is trap-and-emulate. The guest kernel runs without full privilege, so a privileged instruction traps to the hypervisor. The hypervisor then performs the equivalent action on that VM's virtual state and resumes the guest. In 1974 Gerald Popek and Robert Goldberg showed this works when every sensitive instruction is also privileged, so that it always traps. The original 32-bit x86 broke this rule: some sensitive instructions ran in user mode without trapping. Engineers worked around it with binary translation, which rewrites those instructions on the fly, and paravirtualization, which modifies the guest to call the hypervisor directly. In the mid-2000s Intel VT-x and AMD-V added hardware support, and later extensions such as Intel's Extended Page Tables let the hardware translate guest memory addresses efficiently.
Hypervisors come in two broad types. A Type 1 or bare-metal hypervisor, such as VMware ESXi, Microsoft Hyper-V or Xen, runs directly on the hardware and is common in data centers. A Type 2 or hosted hypervisor, such as VirtualBox or VMware Workstation, runs as an application on an ordinary OS and is common on desktops.
Virtualization brings strong isolation, since a crash or attack inside one VM stays inside it. It allows consolidation, many lightly used servers sharing one physical machine. It also allows snapshots and live migration, moving a running VM to another host. Containers offer a lighter alternative: they share the host kernel and isolate only processes, files and network views, which makes them faster to start but less isolated than full VMs.
No topics depend on this one yet.