4.2.40 · D5Operating Systems

Question bank — Virtualization — type 1 and type 2 hypervisors

2,845 words13 min readBack to topic

Before you start, three words must already mean something to you. If any feels fuzzy, re-read the parent note first:


Picture the two stacks first

Before any question, burn this diagram into your head. Count the boxes between the guest and the silicon — that count is the whole Type 1 / Type 2 distinction. Follow the red arrow: it is the data path a hardware request takes.


Picture the trap mechanism

The whole magic of a hypervisor is the trap. This needs the idea of privilege rings: the CPU has concentric permission levels. Ring 0 (innermost) can run any instruction; outer rings are fenced off from dangerous ones. Here is a self-contained sketch so you need not click away (deeper: CPU Privilege Rings).


Why a non-trapping instruction breaks everything

This is the classic x86 trap. Walk the two panels of the figure left to right.


Memory virtualization — the two-level address problem

A guest OS builds its own page tables, mapping guest-virtualguest-physical. But "guest-physical" is a lie — it is not real RAM. So there must be a second translation: guest-physical → host-physical (real RAM). Two levels, not one.


I/O virtualization — three ways to reach a device

The parent note only says "I/O overhead." Here is why it exists and how it is fought, worst-to-best:


True or false — justify

TRUE or FALSE: A Type 1 hypervisor means the machine has no operating system running anywhere.
FALSE. There is no separate general-purpose host OS beneath the hypervisor, but each guest runs a full OS, and the thin hypervisor is itself a small specialized OS on the metal.
TRUE or FALSE: In a Type 2 setup, the host OS still owns and controls the physical hardware.
TRUE. The Type 2 hypervisor is just an application; the host OS schedules it, and every hardware request the guest makes ultimately passes through that host OS.
TRUE or FALSE: A Type 1 hypervisor boots the machine by itself, before any guest exists.
TRUE. It is the base software on bare metal, so it starts at power-on like a normal OS would; guests are created afterward on top of it.
TRUE or FALSE: A Type 2 hypervisor boots the machine by itself.
FALSE. It is launched like any other program after the host OS has already booted and taken control of the hardware.
TRUE or FALSE: A hypervisor simulates every guest instruction one at a time in software.
FALSE. That describes a pure emulator (e.g. QEMU alone). A hypervisor runs most guest instructions directly on the real CPU and only traps the privileged/sensitive ones.
TRUE or FALSE: Because it has an extra layer, a Type 2 hypervisor is always dramatically slower than Type 1 for all work.
FALSE. With hardware assist (VT-x/AMD-V), CPU-bound work is near-native; the extra host-OS hop mainly hurts I/O, not raw computation.
TRUE or FALSE: More stacked layers (host OS + hypervisor) automatically make Type 2 more secure.
FALSE. The host OS adds its entire vulnerability set as attack surface. Type 1's thin hypervisor has a smaller trusted computing base, generally making it more secure.
TRUE or FALSE: KVM is a Type 2 hypervisor because it lives inside Linux.
FALSE (effectively Type 1). KVM is a kernel module that turns the Linux kernel itself into the bare-metal hypervisor — there is no separate host-app layer between guest and privileged VMM.
TRUE or FALSE: Popek & Goldberg say a machine is trap-and-emulate virtualizable only if every sensitive instruction is also privileged.
TRUE. If a sensitive instruction (one that reads or changes machine state) did not trap outside kernel mode, the hypervisor could never intercept it — old x86 broke exactly this rule.
TRUE or FALSE: Guests in both Type 1 and Type 2 run their guest kernel at the most privileged CPU level.
FALSE. The guest kernel is dropped to a less privileged level so its privileged instructions trap up to the hypervisor, which sits at the most privileged level. See CPU Privilege Rings.
TRUE or FALSE: EPT/NPT (hardware nested page tables) help Type 1 but not Type 2.
FALSE. Nested page tables are a CPU feature; any hypervisor exposing them — Type 1 or Type 2 — gets the same two-level translation speedup.
TRUE or FALSE: SR-IOV lets several VMs share one physical NIC at near-native speed.
TRUE. SR-IOV splits one physical device into hardware "virtual functions," each passed straight to a VM, so they bypass most software-emulation overhead.

Spot the error

What is wrong with: "ESXi is Type 2 because you install it like software onto a server."?
Installing it does not make it hosted. ESXi replaces any OS and boots the bare metal itself — nothing runs beneath it, so it is Type 1.
What is wrong with: "VirtualBox on Windows is Type 1 because the Ubuntu guest runs a real Linux kernel."?
The guest running a real kernel is irrelevant to the type. VirtualBox is a Windows application sitting on the host OS, so it is Type 2 — the classification is about what sits on the metal, not what the guest runs.
What is wrong with: "A hypervisor is just an emulator with a nicer name."?
An emulator interprets every instruction in software (slow); a hypervisor executes guest code natively on the CPU and only traps dangerous instructions, so they are architecturally different, not renamed.
What is wrong with: "Type 1 has zero performance overhead because there are no layers."?
There is still one layer (the hypervisor) plus trap-and-emulate costs and I/O virtualization overhead. Type 1 is lower overhead than Type 2, not zero.
What is wrong with: "Because old x86 was hard to virtualize, no one could ever run VMs on it."?
They could, via workarounds: binary translation (rewrite bad instructions), paravirtualization (modify the guest), and later hardware-assisted virtualization (VT-x/AMD-V) which made non-trapping instructions trap cleanly.
What is wrong with: "Type 1 and Type 2 differ mainly in how fast the guest OS is coded."?
The guest OS coding is unrelated. The only defining difference is architectural: what layer sits directly on the hardware (hypervisor for Type 1, host OS for Type 2).
What is wrong with: "Memory virtualization needs only one page-table translation, same as a normal OS."?
There are two levels: guest-virtual → guest-physical (by the guest) then guest-physical → host-physical (by the hypervisor/EPT/NPT). Ignoring the second level is the error.

Why questions

WHY is a Type 2 request slower than a Type 1 request for the same hardware operation?
A Type 2 request travels guest → hypervisor → host OS → hardware, adding one extra layer crossing (the host OS) that Type 1 deletes, so it accumulates more latency.
WHY does the guest kernel have to be dropped to a lower privilege level at all?
So that when it runs a privileged instruction the CPU traps into the hypervisor instead of really executing it — that trap is the mechanism letting the hypervisor safely fake the result for each guest.
WHY did the POPF instruction break naive x86 virtualization?
POPF is sensitive (it can change interrupt flags) but did not trap in user mode — it silently misbehaved, violating Popek & Goldberg, so the hypervisor never got a chance to intercept and emulate it.
WHY are hardware nested page tables (EPT/NPT) faster than shadow page tables?
Shadow tables force the hypervisor to trap every guest page-table edit and rebuild a combined map; EPT/NPT let the CPU walk both translation levels itself, so those edits need no trap.
WHY does paravirtualized virtio I/O beat emulated device I/O?
An emulated device traps and translates on nearly every access; virtio uses a shared ring buffer so the guest and hypervisor batch requests, cutting the number of costly traps dramatically.
WHY is Type 1 generally considered more secure despite doing "less"?
A thinner hypervisor means a smaller trusted computing base — less code that must be trusted and fewer places for bugs, whereas Type 2 also exposes the whole host OS as attack surface.
WHY do data centers and clouds prefer Type 1 while laptops/dev machines prefer Type 2?
Type 1 maximizes performance and isolation on dedicated hardware (worth the harder setup for Cloud Computing); Type 2 wins on convenience — install and run alongside your normal desktop without dedicating the machine.
WHY is trap-and-emulate faster than full emulation?
Because only the rare privileged instructions incur the costly trap-and-fake; the overwhelming majority of guest instructions execute directly on the real CPU at native speed.

Edge cases

EDGE CASE: A Type 1 hypervisor is booted but you create zero VMs — what is it doing?
It still runs as the base software on the metal, managing hardware and waiting; it is a valid (if idle) hypervisor, showing Type 1 exists independently of any guest.
EDGE CASE: You run VirtualBox (Type 2) inside an ESXi (Type 1) guest — what is this called?
Nested virtualization: a hypervisor running inside a VM. Each layer adds another trap-forwarding hop, so it works but stacks overhead and needs hardware/hypervisor support.
EDGE CASE: A "hypervisor" that interprets every guest instruction in software with no native execution — is it a Type 1/Type 2 hypervisor?
No — that is a pure emulator. Type classification applies to hypervisors that run guests natively and trap; an emulator does not trap-and-emulate, it simulates everything.
EDGE CASE: KVM technically needs the Linux userspace tool QEMU to launch VMs — does that make it Type 2?
No. QEMU here provides device emulation/user-space glue, but the privileged VMM is the Linux kernel on the metal, so KVM stays effectively Type 1 (the classic hybrid answer).
EDGE CASE: Xen runs a special Linux VM called dom0 to drive the real devices — does that make Xen Type 2?
No. Xen's thin hypervisor boots the metal first (Type 1); dom0 is a privileged guest it delegates device I/O to, not a host OS beneath it. This split dom0/domU design is the classic "is it Type 1 or 2?" trap — still Type 1.
EDGE CASE: On a CPU with no VT-x/AMD-V support, can you still run a Type 1 hypervisor?
Yes, but it must use binary translation or paravirtualization to handle the non-trapping sensitive instructions; hardware assist is preferred, not strictly mandatory, for the guest to run correctly.
EDGE CASE: You give one VM an SR-IOV pass-through NIC, then try to live-migrate it — what breaks?
The VM is bound to a physical device, so migration is hard: that exact hardware does not exist on the destination host, sacrificing the portability that pure software I/O keeps.
EDGE CASE: Is a container (like Docker) just a very light Type 1 hypervisor?
No. A container shares the host kernel and isolates processes, running no guest OS kernel of its own — so it is not a hypervisor at all. See Containers vs Virtual Machines.

Recall One-sentence self-test

Given any product name, can you decide its type by asking a single question? The single question ::: "What sits directly on the bare metal — this hypervisor (Type 1) or a general-purpose host OS (Type 2)?"

Related: Operating Systems · Processes and Context Switching · Memory Management · 4.2.40 Virtualization — type 1 and type 2 hypervisors (Hinglish)