Virtualisation¶
Exercise virtualisation-annex.pdf · PDF
In the next three weeks you will install Debian, Ubuntu Server and Windows 11. How many PCs do you have? One. And you are not allowed to erase its Ubuntu. So how?
You could buy a second disk, or carry three USB sticks, or ask for three PCs each. Or you could build three computers out of software, all running at the same time inside one real machine. That is what every cloud provider sells, what the Android emulator on a programmer's laptop is, and what you will do tomorrow.
What you will learn
- Define virtual machine, host, guest and hypervisor, and point at each in a drawing
- Give the reasons to virtualise: test, isolate, recover, share
- Tell a type 1 hypervisor from a type 2, with examples of each
- Explain what KVM, QEMU, libvirt and virt-manager each do, and why the CPU must help (VT-x / AMD-V)
- Say where the virtual machines of this course really run: on the class server, not on your PC
- Check with commands, over SSH, whether the host is ready to run virtual machines
- Why a virtual machine never gives your PC more power — it only divides what is there
One kitchen, three restaurants¶
Some restaurants on delivery apps have no dining room at all. Several brands cook in one shared kitchen, and the customer never knows.
The shared kitchen (we keep it all page)
Picture one big kitchen with three brands inside. Each brand has its own manager and its own recipes, and believes the kitchen is all its own. Above them all, one coordinator gives each brand a share of the chefs' time, a piece of countertop and a locked cupboard in the pantry.
Now translate it:
| In the kitchen | In the computer | What it is |
|---|---|---|
| The real kitchen | Host | The real machine, with its own operating system |
| One brand | Virtual machine (VM) | A computer made of software: virtual CPU, RAM, disk and network card. It starts, it has a firmware, it runs its own OS |
| The brand's own manager | Guest | The operating system installed inside a VM |
| The coordinator | Hypervisor | The software that creates the VMs and shares the real hardware among them |
| A share of the chefs' time | vCPU | A virtual processor: time on a real core |
| A piece of countertop | RAM of the VM | Real RAM, reserved for that VM while it runs |
| A locked cupboard | Virtual disk | A file on the host's disk |
flowchart TB
subgraph VMS ["Virtual machines"]
direction LR
subgraph VM1 ["VM: deb-lab"]
A1["Apps"] --- G1["<b>Guest</b><br>Debian 13"]
end
subgraph VM2 ["VM: ubu-srv"]
A2["Apps"] --- G2["<b>Guest</b><br>Ubuntu Server"]
end
subgraph VM3 ["VM: win11"]
A3["Apps"] --- G3["<b>Guest</b><br>Windows 11"]
end
end
VMS --> HV["<b>Hypervisor</b><br>the coordinator: shares CPU, RAM, disk"]
HV --> HOS["<b>Host OS</b><br>Linux on the class server"]
HOS --> HW["<b>Host hardware</b><br>the server's real CPU, RAM and SSD"]
The guest does not know it is a guest. Debian inside a VM checks its hardware, loads its drivers and writes to its disk exactly as it would on a real PC. And its "disk" is one file in a folder of the host: delete that file and the whole computer is gone.
Careful: a VM does not give your PC more power
It gives nothing: it divides what there is. Three VMs with 4 GB of RAM each need 12 GB of real RAM.
Why virtualise?¶
| Reason | What it means | Example |
|---|---|---|
| Test | Try a system without touching your own | Try Windows 11 without changing your Ubuntu |
| Isolate | What breaks inside stays inside | Open a suspicious file inside a VM, not on your PC |
| Recover | Save the state of a machine and go back to it later | An update breaks the system; go back to yesterday (Unit 2, snapshots) |
| Share | One big machine runs many small ones | A data centre runs twenty small servers on one: that is the "cloud" |
For a developer this is daily life: one laptop that tests your app on Windows, on Linux and on Android. The Android emulator is a virtual machine.
Careful: dual boot is not virtualisation
Choosing between two systems at start-up is dual boot: one system at a time, each on the real hardware. With a VM both run at once. And the guest does not have to match the host: you will run Windows 11 on a Linux host.
A little history¶
The idea is older than the PC. In the 1960s a computer cost millions and had to be shared. At an IBM research centre in Cambridge, Massachusetts, a system called CP-40 gave each user a complete virtual computer; it was in daily use by 1967. On 2 August 1972 IBM announced it as a product, VM/370.
Then small, cheap PCs arrived and nobody needed it — until PCs became powerful enough to have power to spare. In 1999 a new company, VMware, sold the first program that ran virtual machines on an ordinary PC.
Two kinds of hypervisor¶
Where does the coordinator sit? The classic answer, from research by Popek and Goldberg in 1974, gives two types:
| Type 1 · bare metal | Type 2 · hosted | |
|---|---|---|
| Runs | Directly on the hardware. It is the operating system of the machine | As one more application, on top of a normal operating system |
| Used in | Servers and data centres | A desk: tests, classes |
| Examples | VMware ESXi, Microsoft Hyper-V, Xen, Proxmox VE | VirtualBox, VMware Workstation |
flowchart TB
subgraph T1 ["Type 1: bare metal"]
direction TB
V1["VM · VM · VM"] --> H1["<b>Hypervisor</b>"] --> HW1["Hardware"]
end
subgraph T2 ["Type 2: hosted"]
direction TB
V2["VM · VM"] --> H2["<b>Hypervisor</b><br>an app"] --> OS2["Host OS"] --> HW2["Hardware"]
end
Our tools: virt-manager, libvirt, QEMU, KVM¶
Four pieces of software work together, one on top of the other:
| Layer | Its job |
|---|---|
| virt-manager | The window you click in. It gives orders to libvirt |
| libvirt | The service that keeps the list of VMs and starts and stops them |
| QEMU | The program that plays the hardware of the VM: its disk, its network card, its screen. Written by Fabrice Bellard in 2003 |
| KVM | A module of the Linux kernel (in Linux since version 2.6.20, February 2007; started by Avi Kivity). It lets the guest's code run directly on the real CPU |
flowchart TB
VMM["<b>virt-manager</b><br>the window you click"] -->|"orders"| LV["<b>libvirt</b><br>the list of VMs"]
LV -->|"starts"| Q["<b>QEMU</b><br>imitates disk, network, screen"]
Q -->|"through /dev/kvm"| K["<b>KVM</b><br>kernel module"]
K --> CPU["<b>Real CPU</b><br>with VT-x / AMD-V"]
Is KVM type 1 or type 2? It lives inside the kernel and touches the hardware directly, so it is usually counted as type 1 — even though a normal Linux system runs around it. The two types are a useful map, not a law. Proxmox VE, which you will install later in this unit, is KVM with a web page on top.
Where does the stack run in this course?¶
On two machines. The VMs of this course do not run on the classroom PC. They run on the class server: a real, powerful machine in a data centre that your teacher switches on before each class. The server is the host: libvirt, QEMU and KVM run there. Your classroom PC runs only virt-manager, which shows each VM's screen and sends it your mouse and keyboard — like a remote control.
flowchart LR
subgraph PC ["Your classroom PC (Ubuntu)"]
VMM["<b>virt-manager</b><br>the window you click"]
end
subgraph SRV ["Class server: the host"]
direction TB
LV["<b>libvirt</b><br>your own list of VMs"] --> Q["<b>QEMU</b>"] --> K["<b>KVM</b>"] --> CPU["<b>Real CPU</b>"]
end
VMM -->|"orders, over SSH"| LV
SSH (Secure Shell) is a secure way to log in to one computer from another and type commands on it, as if you were sitting at it.
Every student is a Linux user on the server, with their own libvirt, and sees only their own VMs. Your teacher hands you a slip with three things: the server address, your user name and your password. Your VMs stay on the server from one class to the next. In the kitchen story: the shared kitchen is across town, and your PC is the phone you place your orders with.
The CPU has to help¶
QEMU alone can imitate a whole processor in software — even a different one, like a phone's ARM chip on a PC. That is emulation: it works everywhere, and it is slow.
To run the guest's instructions on the real CPU, the processor itself must offer an extra level of privilege for the hypervisor, beyond the kernel mode you met in OS architecture. Intel calls it VT-x (first processors in November 2005); AMD calls it AMD-V (2006). Without it, no KVM.
It can be switched off in the firmware setup (Unit 1). That is a classic reason for "my virtual machine will not start".
Careful: a VM is not an emulator
An emulator imitates the processor in software. A virtual machine with KVM runs on the real processor at almost full speed; only the devices (disk, network card, screen) are imitated.
Is the host ready?¶
Before building a VM, check that the kitchen can take it. The kitchen is the host — the class server — so that is where you check. Open a terminal on your PC (Ctrl+Alt+T), log in to the server with the user and password from your slip, and run these, in order. The Exercise sheet has a box for each answer.
ssh <user>@<server> # the prompt changes to <user>@si: you are on the server
LC_ALL=C lscpu | grep -i virtualization
grep -E -c "vmx|svm" /proc/cpuinfo
lsmod | grep kvm
ls -l /dev/kvm
virt-host-validate qemu
groups
virsh -c qemu:///session list --all
nproc
free -h
df -h ~/.local/share/libvirt/images
exit # back to your PC
The first time, ssh may ask whether you trust the server's key: answer yes.
What each one tells you:
| # | Command | Good answer | If not |
|---|---|---|---|
| 1 | lscpu |
Virtualization: VT-x (Intel) or AMD-V (AMD) |
No line: the CPU does not offer it, or the machine is itself a VM |
| 2 | grep -E -c ... |
A number greater than 0: one per thread with the flag (vmx = Intel, svm = AMD) |
0: no hardware virtualisation |
| 3 | lsmod |
Two lines: kvm_intel or kvm_amd, and kvm |
Nothing: the module is not loaded, typically because virtualisation is off in the firmware |
| 4 | ls -l /dev/kvm |
A line starting with c: the door through which QEMU talks to KVM |
No such file: no KVM |
| 5 | virt-host-validate qemu |
The first three checks say PASS. Some WARN lines further down are normal |
A FAIL on the first lines |
| 6 | groups |
The word kvm is in the list: you may use /dev/kvm without being administrator |
Tell your teacher |
| 7 | virsh ... list --all |
A table with Id, Name, State: your own libvirt answers. Empty at first; later it lists your VMs, and only yours |
An error: check you typed qemu:///session |
| 8 | nproc, free -h, df -h ... |
The server's CPUs, total RAM and free disk where your virtual disks live: dozens of threads and tens of GiB, shared by the whole class | — |
Verdict: the host is ready when steps 3, 4, 5 and 7 pass.
Why not check the classroom PC?
Because it does not run the VMs: it only needs virt-manager. You can run the same commands on it out of curiosity — but the answers describe your PC, not the host.
The budget: how many VMs fit?¶
These are the three VMs you will build in this unit:
| VM | Guest | vCPU | RAM | Disk |
|---|---|---|---|---|
deb-lab |
Debian 13 with desktop | 2 | 4 GB | 25 GB |
ubu-srv |
Ubuntu Server 26.04 LTS | 2 | 2 GB | 20 GB |
win11 |
Windows 11 | 2 | 4 GB | 64 GB |
| Total | 6 | 10 GB | 109 GB |
On a single PC — your own at home, for example — the rule of the course is: keep 4 GB of RAM for the host. So all three at once need 10 + 4 = 14 GB.
- A PC with 16 GB: all three fit.
- A PC with 8 GB: not all three.
deb-labalone (4 + 4), orubu-srvwith nothing else heavy.
On the class server the same sum is done for the whole class: every classmate's VMs take their RAM from the same host. That is why the rule in class is shut down the VMs you are not using — the server is shared by everyone.
The other two resources are more forgiving:
- Disk: the 109 GB must be free in the end, but virtual disks start small and grow as the guest writes, so the space is not taken on day one.
- vCPUs: 6 vCPUs on a PC with 4 threads still works, because idle VMs give their turn back — time slices again, from What is an operating system?. RAM cannot be lent that way.
Of the three resources, RAM is the one that says no first. Remember it tomorrow when virt-manager asks how much to give.
Finish by writing up three of your checks as a short Markdown note, host-check-surname.md, on your PC, with the lab report template and one verdict line: "The host is / is not ready to run KVM virtual machines because...". Keep it: tomorrow's report starts by saying on which machine the work was done.
Careful: “nothing inside a VM can ever affect my PC”
A VM is well isolated, not magic. It shares the host's network, and it uses the host's RAM and disk.
Key takeaways¶
- A virtual machine is a computer made of software. The real machine is the host; the OS inside the VM is the guest; the hypervisor creates VMs and shares the real hardware among them.
- A VM's virtual disk is a file on the host, and its vCPUs are time on real cores. A VM divides resources; it never adds them.
- Reasons to virtualise: test, isolate, recover, share.
- Type 1 hypervisors run on the hardware (ESXi, Hyper-V, Xen, Proxmox VE); type 2 run as an app (VirtualBox, VMware Workstation). KVM lives in the kernel and is usually counted as type 1.
- The stack: virt-manager → libvirt → QEMU (imitates devices) → KVM (kernel module), which needs VT-x / AMD-V, sometimes switched off in the firmware.
- In this course the host is the class server: libvirt, QEMU and KVM run there, and you check it over SSH. Your PC runs only virt-manager.
- Plan VMs by RAM first: keep 4 GB for the host on a single PC; on the shared server, shut down the VMs you are not using.
Quick check¶
1. What is the host?
- The real machine that runs the virtual machines
- The system installed inside a virtual machine
- The window where the virtual machine is shown
- The file that holds the virtual disk
The host is the real kitchen: the physical PC and its own OS. The system inside the VM is the guest.
2. What does a hypervisor do?
- It creates VMs and shares the real hardware among them
- It makes the real CPU run faster than its clock
- It connects two PCs through the network
- It copies files between the host and the Internet
The hypervisor is the coordinator: it gives each VM its share of CPU time, its own RAM and its own virtual disk.
3. Where does a type 1 hypervisor run?
- Directly on the hardware
- As an application on Windows or Linux
- Inside the guest operating system
- Inside the web browser
A type 1 (bare-metal) hypervisor is the OS of the machine — typical of servers and data centres. A type 2 runs as an application on a normal OS, like VirtualBox.
4. The command grep -E -c “vmx|svm” /proc/cpuinfo prints 0. What does it mean?
- The CPU offers no hardware virtualisation
- No virtual machine is running right now
- KVM is installed and working
- The PC has no RAM left for a VM
vmx (Intel VT-x) and svm (AMD-V) are the CPU flags for hardware virtualisation. Zero means the CPU does not offer it — or it is switched off in the firmware setup.
5. On the host, the disk of a virtual machine is...
- a file
- a second SSD
- a part of the RAM
- a USB stick
The guest believes it has a disk of its own, but on the host it is just a file. Delete that file and the whole virtual computer is gone.
6. Why does a VM with KVM run much faster than pure emulation?
- The guest's code runs directly on the real CPU, and only the devices are imitated
- KVM gives the guest more cores than the host has
- KVM compresses the guest so it needs less RAM
- The guest switches off the host's operating system while it runs
Emulation imitates the whole processor in software, which is slow. With KVM and VT-x / AMD-V, the guest runs on the real CPU at almost full speed; QEMU only imitates disk, network and screen.
7. A PC has 8 GB of RAM and 4 threads. You want deb-lab (4 GB), ubu-srv (2 GB) and win11 (4 GB). Pick the two that are true.
- Running all three at once is not possible if the host keeps 4 GB
- Six vCPUs on 4 threads can still work, because idle VMs give their turn back
- The VMs will add their RAM to the host, so 18 GB will be available
- The disks must have all 109 GB free before the first VM starts
All three need 10 GB plus 4 GB for the host: 14 GB, far above 8. vCPUs are time slices, so they can be shared; RAM cannot be lent. Virtual disks grow as they fill, so the space is not taken on day one.
8. In this course, where do libvirt, QEMU and KVM run?
- On the class server, which is the host
- On the classroom PC, next to virt-manager
- Inside each guest, one copy per VM
- Half on the classroom PC and half on the server
The host is the class server: it lends the CPU, RAM and disk, so the hypervisor stack runs there. The classroom PC runs only virt-manager, which sends orders over SSH and shows the VM's screen.
Next: open virt-manager and build your first virtual machine — Your first VM with virt-manager.