
Recall first from Emulation, virtualization and containers
- Emulation interprets or translates every guest instruction in software; virtualization runs most guest instructions natively on the same ISA.
- A container shares the single host kernel, which is the root of its weaker isolation.
- Emulation wins cross-architecture work, virtual machines win cloud tenancy, and containers win fast, dense application delivery.
Type 1 and Type 2 hypervisors
2 min readThe previous lesson separated the three techniques and named the hypervisor's parts. This lesson answers how hypervisors are classified into two types and how the two Linux tools, QEMU and KVM, split the work.
Hypervisors are traditionally split into two classes by where they sit.
A a hypervisor that runs directly on the bare hardware with no general-purpose operating system beneath it, sometimes called bare-metal or native is the base layer of the software stack. It boots first, takes ownership of the CPU, memory, and devices, and then starts its guests. Because nothing sits between it and the hardware, it has the smallest possible trusted base and the most direct control. The classic examples are VMware ESXi, Microsoft Hyper-V, the Xen hypervisor, the ACRN hypervisor built for automotive and industrial use, and the Jailhouse partitioning hypervisor.
A a hypervisor that runs as an ordinary program inside a host operating system, which owns the hardware beneath it is an application you install. The host OS boots normally, owns all the hardware, and schedules the hypervisor like any other process. The hypervisor then runs its guests using whatever the host OS gives it. The classic examples are Oracle VirtualBox, VMware Workstation, and QEMU running without any hardware acceleration. Type 2 is convenient, because you install it into an OS you already have, but every guest operation that touches hardware has to make a trip through the host OS first, which is one reason Type 2 has historically been slower.
The distinction is about the layer below the hypervisor, not about how sophisticated the hypervisor is.
KVM and the blurring of the two types
2 min readKVM, the the Linux kernel module, usually named kvm, that turns a running Linux kernel into a hypervisor by exposing the CPU's virtualization extensions to userspace, is the example that breaks the clean two-class story, and it is the most important virtualization technology in the Linux world.
Here is the apparent contradiction. KVM is a module inside the Linux kernel. The Linux kernel is an operating system. So by the literal definition of Type 2, "a hypervisor inside a host operating system", KVM is Type 2. Yet KVM is almost always described as a Type 1 hypervisor. The resolution is that the classification is about control, not about location.
When the kvm module is loaded, the Linux kernel itself gains the authority that a Type 1 hypervisor has: it can enter a special hardware mode, at ARM exception level EL2 or the equivalent x86 root mode, where it controls the CPU's virtualization machinery directly. From that mode, the kernel can launch guests whose instructions run directly on the real CPU. The Linux kernel becomes the hypervisor, and the rest of Linux, the scheduler, the memory manager, the drivers, is just one more guest alongside the VMs, a privileged guest that happens to also run the hypervisor. This is the same relationship Xen has with its dom0, and nobody calls Xen Type 2.
The practical meaning is simpler. In a KVM system, the guests run at full hardware-virtualization speed, not through the slow Type 2 path of an application-level hypervisor. The Linux kernel's own process scheduling and memory management are reused rather than duplicated, which is a huge engineering win. And the kernel is the thing that has already been hardened and audited for years. The cost is that the trusted base, the Linux kernel plus its modules, is much larger than Xen's minimal hypervisor, a trade-off you will examine in a later lesson.
The QEMU and KVM split
3 min readQEMU is two tools in one, and separating its two halves is essential to understanding modern Linux virtualization.
QEMU was born as a pure emulator. In that role it uses a piece of software called TCG, the QEMU's dynamic binary translator, which compiles guest machine code into host machine code at run time, to translate the guest's instructions into host instructions and run them. No hardware help is involved, which is why QEMU-TCG can run any guest architecture on any host architecture.
But QEMU has a second role: the the software component that emulates the virtual machine's hardware, such as its disk controller, network card, and console. A guest operating system expects to find a disk controller, a network card, a serial port, and an interrupt controller. QEMU provides all of them in software, and when the guest writes to one of these devices, QEMU intercepts the write and updates its model of the device. This half of QEMU is needed no matter how the guest's CPU instructions are executed, because virtual devices do not exist in hardware.
When you run qemu-system-x86_64 -accel kvm, you are combining the two tools in the classic split. KVM, the kernel module, handles the CPU and memory: it makes the guest's instructions run directly on the real CPU, and it maintains the second-stage page tables that translate the guest's addresses to physical addresses. QEMU, running as an ordinary userspace process, handles everything else: it sets up the machine, emulates the devices, and calls into KVM through the /dev/kvm device file every time it needs the kernel to run the guest for a while. The userspace QEMU is the VMM, and the kernel KVM is the CPU and memory virtualization engine.
QEMU sets up: QEMU creates the virtual machine, allocates its memory, and emulates the device model.
QEMU calls KVM: QEMU issues an ioctl on /dev/kvm asking the kernel to run the guest's vCPU.
KVM runs the guest: the kernel enters guest mode, and the guest's instructions execute natively on the CPU.
The guest traps: a privileged instruction or device access causes a VM exit back into the kernel.
KVM decides: the kernel either handles the exit itself or reports it back to QEMU.
QEMU reacts: QEMU emulates the device the guest touched, then asks KVM to resume the guest.
Key takeaways
- Type 1 hypervisors run on bare metal; Type 2 run on top of a host OS, but KVM blurs the line because the hypervisor is the kernel.
- When the kvm module loads, the Linux kernel gains EL2 or root mode authority and becomes the hypervisor, with the rest of Linux as a privileged guest.
- QEMU provides the device model in userspace while KVM runs guest CPU and memory in the kernel, and QEMU calls KVM through /dev/kvm.
Reflect
- Explain to a colleague, in two sentences: classify Xen, ESXi, Hyper-V, KVM, VirtualBox, and QEMU-TCG as Type 1 or Type 2 and justify each.
- Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
- What surprised you when you ran the commands yourself?
On a real board
Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.
References and further reading
Official documentation first. Links checked when the lesson was published.