Virtualization
Exam 306 separates virtualization from containerization because a hypervisor runs a full guest kernel on emulated or paravirtualized hardware, while containers share the host kernel. This domain tests how KVM, QEMU and libvirt divide the work, and how you define, boot, network and store virtual machines from the shell.
The stack
- KVM is the in-kernel hypervisor exposed as /dev/kvm: it virtualizes CPU and memory but emulates no devices.
- QEMU is the userspace device model (chipset, disk controllers, NICs).
-accel kvmis what makes it near-native; without it QEMU interprets instructions. - libvirt is the management layer.
libvirtd, or the newer modularvirtqemud, exposes an API used byvirsh,virt-installandvirt-manager. Domains are XML documents, edited withvirsh edit.
Storage and networking
qemu-img create -f qcow2 d.qcow2 20Gmakes a sparse image:qemu-img inforeports 20 GiB virtual size but a small disk size that grows on write. Raw images are fully allocated and cannot hold internal snapshots.- The
defaultnetwork is NAT on virbr0 (192.168.122.0/24) served by dnsmasq: guests reach out, the LAN cannot reach in without forwarding. - Bridged guests need a host bridge declared as
<interface type='bridge'>. macvtap is the bridge-free option, but itsbridgemode blocks host-to-guest traffic. virsh domifaddrreads from the qemu-guest-agent; with no agent channel defined it returns nothing even on a healthy guest.
Worked example
Grow a running VM disk by 10 GiB. virsh domblklist web01 shows vda mapped to web01.qcow2. Run qemu-img resize web01.qcow2 +10G: qcow2 supports growing virtual size online. The guest sees a larger block device, but the partition table and filesystem above it are unchanged, so run growpart /dev/vda 1 then resize2fs /dev/vda1. The reasoning is layered: qemu-img edits the image only. Shrinking reverses the order, and --shrink refuses below the highest allocated cluster anyway.
Traps that cost marks
virsh destroyis a hard power-off, not a delete. Remove a domain withvirsh undefine; add--remove-all-storageto drop volumes too.- Hand-editing /etc/libvirt/qemu/*.xml skips schema validation and libvirt may overwrite it; use
virsh edit. - The default NAT network is not autostarted everywhere:
virsh net-autostart default. - Live
virsh setmemneeds the virtio-balloon driver in the guest.