Origin Academy
← Back to course

Virtualization Engineer (QEMU & KVM) Phase 0 is free

Join the waitlist

Phase 0 · Module 1 of 4

Hypervisors: type 1, type 2, and where QEMU and KVM fit

Type 1 and type 2 hypervisors · 10 min read

A hypervisor runs virtual machines: it gives each guest operating system the illusion of having a whole computer to itself, while sharing one real machine between them. Every cloud server you have ever used was almost certainly a VM.

Type 1 and type 2

  • Type 1 (bare-metal) hypervisors run directly on the hardware, with no general-purpose OS underneath. Xen and VMware ESXi are classic examples.
  • Type 2 (hosted) hypervisors run as programs on top of a normal OS. VirtualBox and VMware Workstation are examples.

KVM blurs the line. It is a module inside the Linux kernel that turns Linux itself into a hypervisor, using the CPU's virtualization extensions (Intel VT-x or AMD-V). QEMU is the user-space program that creates the virtual hardware around the guest: disks, network cards, the display. Together, QEMU and KVM power a large part of the world's clouds.

Emulation versus virtualization

QEMU can also run guests without KVM, by translating every guest instruction in software (its TCG engine). That lets you run an ARM guest on an x86 laptop, but it is much slower. With KVM, guest code runs directly on the real CPU, and only sensitive operations trap back to the hypervisor.

Check your machine

$ grep -cE 'vmx|svm' /proc/cpuinfo   # CPUs with VT-x (vmx) or AMD-V (svm)
8
$ lsmod | grep kvm                    # is the KVM module loaded?
kvm_intel             ...
kvm                   ...
$ ls -l /dev/kvm                      # the device QEMU opens to use KVM
crw-rw---- 1 root kvm 10, 232 ... /dev/kvm

If the first command prints 0, virtualization is disabled in your firmware settings or you are already inside a VM without nested virtualization. If /dev/kvm exists but you can't open it, add yourself to the kvm group. Your output will differ in the details.

Try it

  • Run the three checks above and explain each line of the output.
  • Is the machine you use for work a VM? Find out with systemd-detect-virt, then explain what the answer means.

In the full course you go from here to booting guests with QEMU, cross-architecture emulation, writing a tiny hypervisor against the /dev/kvm API in C, virtio devices, libvirt, live migration and writing your own emulated PCI device.

Next in Phase 0

Privilege levels and trap-and-emulate

Continue →