Appendix A: Cheat Sheet
Everything at a glance, sorted by topic.
The lab
| What | Where |
|---|---|
| kvm1 | 172.16.0.182, bridge br0 with a fixed address (Day
6) |
| kvm2 | 172.16.0.123, second host from Day 7 on |
Network default |
NAT, 192.168.122.0/24, virbr0 |
Network intern |
isolated, 10.10.10.0/24, virbr1, domain
intern, db .20, notes .30 |
Network lan |
bridge network on br0, addresses from the LAN |
| Pools | default, basis, boot-scratch,
lab, vgkvm (LVM on loop),
nfs |
| Base image | /var/lib/libvirt/images/basis/noble.qcow2,
chmod 444 |
| Logs | /var/log/libvirt/qemu/<vm>.log,
journalctl -u libvirtd, journalctl -k |
| Cockpit | https://172.16.0.182:9090, ubuntu /
lab-console-pw-123 |
| notes-api | http://<LAN IP of notes>:8080, API key
lab-api-key-123 |
QEMU and qemu-img
| Task | Command |
|---|---|
| VM by hand | qemu-system-x86_64 -enable-kvm -cpu host -m 1024 -smp 2 -drive file=…,if=virtio -nic user,hostfwd=tcp::2222-:22 -nographic |
| Monitor | Ctrl+A c, info kvm, info block; back with
Ctrl+A c |
| Disk | qemu-img create -f qcow2 x.qcow2 10G |
| Overlay | qemu-img create -f qcow2 -b basis.qcow2 -F qcow2 x.qcow2 |
| Info | qemu-img info [-U] --backing-chain x.qcow2 |
| Convert | qemu-img convert -O qcow2 [-c] quelle ziel |
| Internal snapshot | qemu-img snapshot -c/-l/-a/-d name x.qcow2 |
| Re-point base | qemu-img rebase -u -b neu.qcow2 -F qcow2 x.qcow2 |
| Size | qemu-img resize x.qcow2 +5G |
| Seed ISO | cloud-localds seed.iso user-data [meta-data] |
virsh by object
| Object | Common |
|---|---|
| Domain | list --all, define,
undefine [--remove-all-storage], start,
shutdown, destroy, reboot,
autostart |
| Domain info | dominfo, dumpxml [--inactive],
domblklist, domiflist,
domifaddr [--source agent],
domstate --reason |
| Resources | setmem --live, setmaxmem --config,
setvcpus --config [--maximum], vcpupin,
emulatorpin, iothreadadd |
| Disks | attach-disk … --subdriver qcow2 --persistent,
blockresize,
blockcommit --active --shallow --pivot |
| Network cards | attach-interface … --model virtio --persistent,
detach-interface <type> --mac … |
| Snapshots | snapshot-create-as [--disk-only --atomic --diskspec …],
snapshot-list, snapshot-revert,
snapshot-delete [--metadata] |
| Backups | backup-begin [backup.xml checkpoint.xml],
domjobinfo --completed, checkpoint-list |
| QEMU guest agent | guestinfo, domfsinfo,
set-user-password,
domfsfreeze/domfsthaw,
qemu-agent-command |
| Networks | net-list --all, net-define,
net-start, net-autostart,
net-update … ip-dhcp-host,
net-dhcp-leases |
| Pools | pool-define-as, pool-build,
pool-start, pool-autostart,
pool-refresh, vol-list,
vol-create-as, vol-delete |
| Migration | migrate --live|--offline [--persistent --undefinesource] [--copy-storage-all] vm qemu+ssh://ziel/system |
| Observing | event --all --loop, domstats,
dommemstat, virt-top |
Tools around virsh
| Tool | Purpose |
|---|---|
virt-install --import --cloud-init user-data=…,meta-data=…,network-config=… |
build a VM from a cloud image |
virt-install --print-xml --dry-run |
view the XML without creating anything; without
--dry-run the disk is still created (Day 4) |
virt-xml <vm> --edit … /
--add-device … |
change the definition without an editor |
virt-clone --original … --name … --auto-clone |
full copy of a powered-off VM |
virt-sysprep -d … --operations machine-id,ssh-hostkeys,customize … |
strip a clone of its identity |
virt-cat -d vm datei /
virt-ls -a image -m /dev/sda / |
read from disks without booting |
virt-admin daemon-log-filters/-outputs |
debug logging at runtime |
virt-host-validate |
check the host |
Domain XML: the most important places
<memory>, <currentMemory>, <vcpu> memory and CPUs
<cpu mode='host-passthrough'/> pass through the host CPU
<memoryBacking> hugepages, memfd + shared (virtiofs)
<iothreads>, <cputune> IOThreads and pinning
<on_reboot> destroy during the installation phase!
<disk type='file'> disk; <driver cache='none' io='native' iothread='1'/>
<interface type='network'> network card; <mac address='52:54:00:…'/>
<filesystem><driver type='virtiofs'/> share from the host
<channel> org.qemu.guest_agent.0 channel for the QEMU guest agent
<graphics type='spice' listen='127.0.0.1'> console
<seclabel model='apparmor'|'dac'> security label
Typical errors
| Message | Cause | Day |
|---|---|---|
Cannot access storage file '…' (as uid:64055, …): Permission denied
for a disk in /home |
libvirt-qemu may not read there |
3 |
VM off after virsh reboot |
first installation phase, on_reboot destroy |
4 |
| Clone without an IP | netplan bound to the old MAC | 5 |
Failed to autostart VM … /dev/vgkvm/… |
loop device missing after reboot | 8 |
Could not open … noble.qcow2 during
blockcommit |
without --shallow, into the base image |
8 |
Cannot store dirty bitmaps in qcow2 v2 files |
disk with compat: 0.10 in the checkpoint |
8 |
Migration disabled: vhost-user backend … |
virtiofs prevents snapshots with RAM and migration | 9 |
io='native' needs either no disk cache… |
io=native only with cache=none |
10 |
unable to map backing store for guest RAM |
hugepages not reserved | 10 |
mount: … bad option for the NFS pool |
nfs-common missing |
12 |
Unable to resolve address 'kvm2' service '49152' |
target name not in /etc/hosts |
12 |
Network not found: … 'intern' during migration |
network missing on the target | 12 |
network 'test' is not active |
network defined, not started | 14 |
VMs without network after
net-destroy/net-start |
tap devices no longer attached to the bridge | 15 |