Fake hardware convincing enough to boot: type 1, type 2, and what a VM actually is.
For your capstone Take your own app to production
Your app will most likely run on a rented server, and that server is a guest on the provider's hypervisor, often sharing a physical host with other customers' guests. Its vCPUs and memory are things the host schedules and maps for it, and some of its strangest symptoms come from the layer below.
Say your app's requests slow down every evening around 20:00, yet top on the server shows your own processes using only a third of the CPU. The st column reads 25.0: a quarter of the time, your vCPUs were ready to run but the host was running something else. Nothing in your code changed, and no amount of tuning it will move that number. It is the host, and a dedicated host or bare metal is what takes the neighbors away.
Check your own machine
These commands only read information — they change nothing. Run the
block for your OS, then use the table to read your own numbers
against the ideas above.
What you should see The first line prints a small table: HypervisorPresent is True when a hypervisor is running underneath this Windows; inside a VM, Manufacturer and Model often name the virtual platform. The second prints a list, one property per line with its value after a colon: the processor's name, then True or False for whether virtualization is enabled in firmware, whether the CPU has virtualization extensions, and whether it has second-level address translation.
Note HypervisorPresent can be True on a physical PC too: turning on Hyper-V, WSL 2, virtualization-based security (memory integrity), which is on by default on many new PCs, or other features built on the Windows hypervisor puts Windows itself in the root partition above it. When a hypervisor is already running, VMMonitorModeExtensions and SecondLevelAddressTranslationExtensions read False even though the CPU supports them, while VirtualizationFirmwareEnabled can still read True; in that case HypervisorPresent True is the answer that counts.
What you should see kern.hv_support: 1 means this Mac can host VMs through the hypervisor built into macOS; 0 means it cannot. kern.hv_vmm_present: 1 means this copy of macOS is itself running as a guest inside a VM; 0 means it is running on the Mac's own hardware.
Note Both values only read state; neither command changes anything. Older macOS releases may not have kern.hv_vmm_present and print an unknown oid message instead.
What you should see On a physical machine with virtualization enabled, lscpu prints a Virtualization line naming VT-x (Intel) or AMD-V (AMD). Inside a VM it also prints Hypervisor vendor (for example KVM or Microsoft) and Virtualization type: full. The grep prints ept (Intel) or npt (AMD) when the processor offers second-level address translation, and prints nothing otherwise.
Note If the Virtualization line is missing on a physical machine, the feature may be switched off in the firmware settings or absent from the CPU. Inside a VM or WSL the lines describe the virtual CPU the hypervisor chose to present, so support can look missing even when the real CPU has it.
What you should see systemd-detect-virt --vm prints a short name for the hypervisor this system runs under, such as kvm, microsoft, vmware or oracle, or prints none on bare hardware. ls shows /dev/kvm as a character device when the kernel's KVM hypervisor is loaded; whether your account can use it depends on the device's group, usually kvm, shown in the same line. A No such file or directory message means this kernel cannot host KVM guests right now.
Note Under WSL 2 this prints microsoft, because WSL 2 runs its Linux kernel in a lightweight VM on the Windows hypervisor. On systems without systemd the command may be missing; the lscpu Hypervisor vendor line answers the same question.
Where each idea shows up in your output
Concept
Windows
macOS
Linux
The CPU has hardware virtualization extensions
VMMonitorModeExtensions and VirtualizationFirmwareEnabled (the first reads False when a hypervisor is already running; then HypervisorPresent True is the answer)
kern.hv_support: 1
lscpu Virtualization: VT-x or AMD-V
The CPU has second-level address translation
SecondLevelAddressTranslationExtensions (also reads False when a hypervisor is already running)
—
ept or npt in /proc/cpuinfo
This operating system is running as a guest
HypervisorPresent (also True in a Hyper-V root partition)
kern.hv_vmm_present: 1
lscpu Hypervisor vendor; systemd-detect-virt --vm
This kernel can act as a hypervisor
—
kern.hv_support: 1
/dev/kvm exists
The same ideas, as prose
These are the exact fragments the model serves — also available as an
ordered study guide.
A whole computer, made of software
A virtual machine (VM) is a complete computer that exists as software running on another computer. It has what looks like a processor, memory, a disk and a network card; it boots its own operating system from scratch, kernel and all; and that operating system, the guest, goes about its business as if the hardware were real. Some of it is. The guest's instructions run on the real processor and its data sits in real RAM, but the machine those pieces add up to is assembled and policed by software, like a film set, where the actors play their scenes normally and some of the props are real, but the street around them is put together and kept running by a crew behind the facade.
The software doing the assembling is the hypervisor, also called a virtual machine monitor. It sits between the guests and the physical machine, the host, and it has three jobs: share the real CPUs among the guests, give each guest a private view of memory that it takes to be the whole of RAM, and present devices, a disk or a network card, that are partly or wholly imaginary. In the classic arrangement it does all three without the guest's cooperation, and without the guest being able to tell.
That is the whole idea, and everything else is detail about how to keep the pretense up cheaply: how the guest's own code runs directly on the processor while still being watched, why it got much faster once processors started helping, the two textbook ways a hypervisor can be installed and why real systems blur them, and what a VM costs compared with what it buys.
What the guest sees
Every piece of hardware a guest sees is backed by something different on the host: its virtual CPUs are threads the host schedules on real cores, its physical RAM is a slice of the host's RAM, its disk is a file or volume, and its network card is the host's real connection, with the hypervisor in between.
A guest operating system boots the way it would on a physical computer: firmware first, then a bootloader, then its own kernel. What it finds is whatever virtual hardware the hypervisor has decided to present: some number of virtual CPUs (vCPUs), a block of memory it treats as physical RAM, one or more disks, and a network card. A guest configured with two vCPUs and four gigabytes of memory sees a two-processor, four-gigabyte computer, whatever the host underneath actually has.
None of those parts is what it claims to be. Each vCPU is something the host schedules onto its real cores, alongside everything else the host is running. The guest's physical memory is a slice of the host's RAM that the hypervisor has set aside and maps on the guest's behalf. The virtual disk is backed by a file or a volume on the host's storage, and the network card's traffic ends up on the host's real network connection; how each of those is wired up belongs to the concepts on snapshots and on virtual networking.
The illusion holds because a guest can only reach hardware through a few doors: executing instructions, reading and writing memory addresses, and talking to device registers. Control those doors and you control what the guest believes. The hypervisor does not need to fool the guest's applications at all; it only has to fool the guest's kernel, and the applications inherit the illusion from it.
Virtual CPUs take turns on real ones
On one physical core, guest code runs directly on the CPU until a sensitive operation or the end of its time slice forces a VM exit to the hypervisor, which handles it and then either re-enters the guest where it left off or runs another guest's vCPU.
A vCPU is not a slice of silicon. It is a saved processor state, the guest's registers, its instruction pointer and its privileged settings, that the hypervisor can load onto a physical core and run. While a vCPU runs, the guest's instructions execute directly on the real processor; nothing reads them and replays them one at a time. When it stops, the hypervisor saves that state and the core is free for something else. Sharing cores among vCPUs is the same job an operating system does when it shares cores among processes, and in the typical KVM setup it is literally that job: each vCPU is a thread of an ordinary host process, scheduled by the Linux scheduler like any other thread.
The catch is that the guest kernel believes it is in charge of the machine, and it cannot be allowed to be. Some operations, such as talking to a device, programming the interrupt controller, or halting the processor, would let a guest reach past its own walls if they ran unchecked. The processor is configured so that these sensitive operations do not complete inside the guest; instead they force a VM exit, a switch out of the guest and into the hypervisor. The hypervisor works out what the guest was attempting, carries out a safe version of it on the guest's behalf, and performs a VM entry to resume the guest exactly where it stopped. The pattern is called trap-and-emulate.
Exits are also how the hypervisor takes a core back when a vCPU's time slice is up, so that another guest can run. Every exit is time the guest is not running, which makes exits the main tax on a VM's processor performance: a guest that mostly computes rarely exits and spends nearly all its time running its own instructions directly, while a guest that is constantly poking devices pays on every poke.
Each guest gets its own memory
A memory address in a guest is translated twice: the guest's own page tables turn a guest-virtual address into a guest-physical address, and the hypervisor's second-level table turns that into a host-physical address in real RAM; with EPT or NPT the processor walks both tables in hardware.
Operating systems already give every process a private view of memory. A program works with virtual addresses, and the kernel keeps page tables that tell the processor which physical location in RAM each virtual address really means. A guest kernel does exactly this for its own processes, and it believes the physical addresses it hands out are real. They are not. They are guest-physical addresses, one more layer of fiction, and the hypervisor keeps a second mapping from guest-physical addresses to host-physical ones, the actual locations in the machine's RAM.
So every memory access inside a VM needs two translations: guest-virtual to guest-physical, then guest-physical to host-physical. Before processors could do the second step themselves, hypervisors used shadow page tables: combined guest-virtual-to-host-physical tables that the hypervisor built and loaded into the processor in place of the guest's own, while trapping the guest's changes to its tables so the shadows stayed in step. All that trapping meant frequent exits, and it was one of the largest costs of early virtualization.
Second-level address translation removed most of that work. Intel's version is called Extended Page Tables (EPT) and AMD's is Nested Page Tables (NPT); with either, the processor walks the guest's tables and the hypervisor's tables itself, so the guest can edit its own page tables without the hypervisor intercepting each change. The cost moves rather than vanishes: when the processor has no cached translation for an address, it must walk both sets of tables, which takes more memory reads than a single walk.
The same mapping is what keeps guests apart. A guest can only reach host memory that the hypervisor's table maps for it; an address with no entry there leads nowhere, so one guest has no way even to name another guest's memory.
Hardware help, and why VMs got fast
In 1974 Gerald Popek and Robert Goldberg set out what a processor needs for trap-and-emulate to work: every sensitive instruction, one that reads or changes the machine's privileged state, must also be privileged, so that it traps when a guest runs it outside the most privileged mode. The original x86 broke that rule. Some of its sensitive instructions behaved differently in kernel mode and user mode without trapping, so a guest kernel running with reduced privilege would execute them, quietly get the wrong result, and give the hypervisor no exit to catch.
Two workarounds made x86 virtual machines practical anyway. Binary translation, the approach of early VMware, inspected guest kernel code before it ran and rewrote the troublesome instructions into safe sequences. Paravirtualization, the approach of the early Xen hypervisor, modified the guest kernel so that it made explicit calls to the hypervisor, called hypercalls, instead of executing those instructions, which meant the guest kernel had to be a version ported to cooperate; the applications on top ran unchanged. Both worked, and both were intricate.
Then the processors changed. Intel VT-x shipped in 2005 and AMD-V in 2006, each adding a separate guest mode in which sensitive operations exit to the hypervisor by design, and second-level address translation followed, from AMD in 2007 and Intel in 2008, to take the page-table bookkeeping off the hypervisor too. With the hardware doing the trapping, a hypervisor can run an unmodified guest with no rewriting at all; KVM, first released with Linux 2.6.20 in early 2007, was built on these extensions from the start.
That is what virtualization means here: the guest's own instructions run natively on a processor of the same architecture, with the hypervisor stepping in only at exits. Emulation is a different and much slower thing, needed when the architectures differ: an ARM guest on an x86 host has no x86 instructions to run natively, so an emulator such as QEMU must translate the guest's instructions into host instructions in software, block by block, and keep the imitation ARM processor's state up to date as it goes, which is why such a guest crawls by comparison.
Emulated and paravirtualized devices
With an emulated device, each register access by the guest's ordinary driver traps to the hypervisor, one exit per access; with a paravirtualized device, the guest's virtio driver places many requests in a shared-memory queue and sends one notification, so a whole batch costs a single exit.
Devices are where the illusion costs the most. A device driver works by reading and writing a device's registers, and in a VM every one of those reads and writes has to land somewhere the hypervisor can see it. The oldest answer is the emulated device: the hypervisor imitates a real, widely supported piece of hardware, such as a common network card or disk controller, register by register. The guest's ordinary driver for that hardware works unmodified, which is the whole point, but its register accesses trap to the hypervisor, which then has to act out the device's detailed behavior in software, and a driver written for real hardware makes a lot of those accesses.
A paravirtualized device drops the pretense. It is a device designed for virtual machines, with no physical twin, and the guest runs a driver that knows it is talking to a hypervisor. virtio is the open standard for such devices: the guest driver and the hypervisor share queues in memory, the driver places many requests in a queue, and a single notification tells the hypervisor to process the batch. Less imitation work and fewer exits move the same data, which is why paravirtualized disks and network cards outperform emulated ones; the price is that the guest needs virtio drivers, which current Linux kernels include and Windows guests need added.
The third option is passthrough: hand one guest a real physical device, such as a network card or a graphics card, for its exclusive use. The guest uses the device's own driver and talks to the hardware directly, with the hypervisor out of the data path. An IOMMU, a memory-translation unit that sits in front of devices the way page tables sit in front of programs, confines that device's direct memory access to the guest's own memory, so the guest cannot use it to read or write the host. The cost is flexibility: a device passed to one guest is unavailable to the host and to every other guest.
Type 1, type 2, and the blurry line
A type 1 hypervisor runs directly on the hardware with guests above it; a type 2 hypervisor runs as an application on a host operating system; with KVM the hypervisor lives inside a general-purpose Linux kernel on the hardware, and each virtual machine is an ordinary host process beside other programs.
The textbook split comes from Robert Goldberg's 1973 thesis. A type 1 hypervisor runs directly on the hardware with nothing beneath it, and the guests run on top of it; it is often called a bare-metal hypervisor, and Xen is the standard example. A type 2 hypervisor runs as an application on a conventional operating system, the host, and leans on that host for scheduling, memory and device drivers; desktop VM programs such as VirtualBox, installed on an ordinary laptop, are the familiar case.
Real systems do not stay in those boxes. KVM is a module of the Linux kernel that turns Linux itself into a hypervisor. That kernel runs directly on the hardware, which is why KVM is usually filed under type 1; yet the same kernel is a general-purpose operating system running ordinary programs, and each VM is an ordinary host process, commonly QEMU, whose vCPUs are threads, which is the shape of type 2. Windows has the opposite surprise. When its built-in hypervisor, Hyper-V, is turned on, whether directly or by a feature built on it such as WSL 2 or virtualization-based security (memory integrity), which is on by default on many new PCs, the hypervisor starts at boot beneath Windows, and the Windows installation you log into runs on top of it in a privileged partition called the root partition, which manages the guests and keeps direct access to the hardware. The desktop in front of you is no longer running directly on the machine; it is running on the hypervisor, like the guests, just with special privileges.
So read the label as a statement about where the hypervisor sits, not about how fast or how safe it is. Hypervisors on both sides of the line can use the same processor extensions to run guest code natively; the more useful questions are what runs underneath the hypervisor and what else shares its privileged layer, and the labels answer those only roughly. Proxmox VE, the worked example these pages use for building VMs by hand, shows the blur well. Strictly it is a free, open-source virtualization platform built on Debian Linux, and the hypervisor doing the work for its VMs is KVM; but it installs on a bare machine and exists to run guests, so in everyday terms it is a type 1 hypervisor you can run on one box for free.
What a VM costs, and what it buys
A VM is the expensive way to isolate software, and it is upfront about it. Every guest carries a whole operating system: its own kernel, its own background services, its own file caches, all occupying memory the hypervisor gave it whether the application needs them or not. Starting a guest means booting that operating system, firmware through kernel to services, which takes far longer than starting a process. And every disk read and network packet crosses from guest to hypervisor and back, paying for exits along the way, more with emulated devices and fewer with paravirtualized ones.
What that buys is a strong wall, like detached houses compared with rooms in one shared house: each house pays for its own foundation, roof and plumbing, and that is exactly why a burst pipe in one never floods the neighbors: each guest has its own kernel, so a crash, a faulty driver or a compromised kernel in one guest stays inside that guest's virtual hardware, and reaching a neighbor means getting through the hypervisor itself, which is possible but much harder. How that wall compares with processes kept apart inside one shared kernel is taken up in resource isolation.
The other thing it buys is a choice of operating system. Because each guest brings its own kernel, one machine can run a Linux guest, a Windows guest and a BSD guest side by side, each at its own version, each patched and rebooted on its own schedule. Containers give up both the cost and these two benefits: every container on a host runs on that host's one kernel, which is why containers start in moments and pack densely, and why the comparison between the two belongs to the containers concept.
Promising more than you have
A host with 4 physical cores has handed out 8 vCPUs to two guests: when only a few are busy they all fit on the cores, but when every vCPU is busy at once half of them wait for a core, and that waiting shows up inside each guest as steal time.
A hypervisor does not have to hand out only what it has. Give the guests more vCPUs in total than the host has physical cores, or more guest memory in total than the host has RAM, and the host is overcommitted. It is a bet that the guests will not all want everything at once, like an airline that sells more seats than the plane holds, betting that some passengers will not turn up: it fills the plane efficiently on most days, and goes badly on the day everyone arrives, and for guests that sit partly idle it is a reasonable bet.
CPU overcommit is easiest to see with numbers. Take an illustrative host with 4 physical cores running two guests with 4 vCPUs each: 8 vCPUs handed out on 4 cores, an overcommit ratio of 8 to 4, or 2 to 1. While only three vCPUs are busy, each busy one gets a whole core and the overcommit costs nothing. When all 8 are busy at once, 4 cores shared among 8 runnable vCPUs gives 4 / 8 = 0.5, so each vCPU gets half a core on average and its work takes about twice as long as it would on a core of its own. Inside a Linux guest, time when a vCPU was ready to run but the host was running something else is reported as steal time, the st figure in top: a guest with high steal time is slow not because of its own work but because it is waiting its turn on the host.
Memory overcommit fails more sharply, because memory cannot be taken in turns the way a core can. Hypervisors claw memory back in a few ways. Ballooning uses a driver inside the guest that, at the hypervisor's request, inflates by claiming guest memory and handing it back to the host; the guest then frees up what it can spare elsewhere, ideally caches, so the guest itself chooses what to give up. Page sharing, such as Linux's kernel samepage merging (KSM), finds identical pages in different guests and keeps a single copy. The last resort is the host swapping guest memory out to disk without the guest knowing, which turns what the guest believes is RAM into disk reads, roughly a thousand times slower for a solid-state drive; and if even that is not enough, a Linux host that runs out of memory can kill a VM's process to save itself, which from inside the guest looks like someone pulling the power cord.
When you will feel this
VMs are a unit much of computing is built and rented in. One physical box running a hypervisor becomes several machines: a router in one guest, a file server in another, a risky experiment in a third, each with its own operating system and its own failures. Taking an app to production often means running it on a server from a cloud provider, and a standard rented server there is generally itself a guest on the provider's hypervisor, often sharing a physical host with other customers' guests unless you pay for a dedicated host or bare metal.
Knowing what sits underneath turns some baffling symptoms into ordinary ones. A guest that is slow while its own CPU use looks modest may be waiting for the host, and steal time will say so. A guest with poor disk or network throughput may be using emulated devices where paravirtualized ones are available. A guest that simply vanished may have been sacrificed by a host that ran out of memory after promising more than it had. Each is a property of the layer below, and each stays invisible for as long as you treat the virtual hardware as real.
Two more pieces build directly on this layer: how guests are wired onto networks inside one box, and how a whole machine becomes a file you can freeze, copy and roll back. Both start from the same fact: a VM is a full computer made of software, and the hypervisor decides what that software is allowed to believe.