====== Libvirt tips and tricks ======
===== libvirt machine =====
Display available machine types:
$ qemu-system-x86_64 -machine help | grep -v deprecated
Supported machines are:
microvm microvm (i386)
pc-i440fx-9.2 Standard PC (i440FX + PIIX, 1996)
pc-i440fx-9.1 Standard PC (i440FX + PIIX, 1996)
pc-i440fx-9.0 Standard PC (i440FX + PIIX, 1996)
pc-i440fx-8.2 Standard PC (i440FX + PIIX, 1996)
pc-i440fx-8.1 Standard PC (i440FX + PIIX, 1996)
pc-i440fx-8.0 Standard PC (i440FX + PIIX, 1996)
pc-i440fx-7.2 Standard PC (i440FX + PIIX, 1996)
pc-i440fx-7.1 Standard PC (i440FX + PIIX, 1996)
pc Standard PC (i440FX + PIIX, 1996) (alias of pc-i440fx-10.0)
pc-i440fx-10.0 Standard PC (i440FX + PIIX, 1996) (default)
pc-q35-9.2 Standard PC (Q35 + ICH9, 2009)
pc-q35-9.1 Standard PC (Q35 + ICH9, 2009)
pc-q35-9.0 Standard PC (Q35 + ICH9, 2009)
pc-q35-8.2 Standard PC (Q35 + ICH9, 2009)
pc-q35-8.1 Standard PC (Q35 + ICH9, 2009)
pc-q35-8.0 Standard PC (Q35 + ICH9, 2009)
pc-q35-7.2 Standard PC (Q35 + ICH9, 2009)
pc-q35-7.1 Standard PC (Q35 + ICH9, 2009)
q35 Standard PC (Q35 + ICH9, 2009) (alias of pc-q35-10.0)
pc-q35-10.0 Standard PC (Q35 + ICH9, 2009)
isapc ISA-only PC
none empty machine
x-remote Experimental remote machine
Basically **pc-i440fx** is old hardware (no UFI boot etc) for old software and **pc-q35** is new hardware what you probably need. Then version number is a frozen state of the machine specs, use the latest one except if you need to migrate the VM between different versions of qemu, in this case use highest version supported by all version of qemu you have.
Choosing an alias **q35** here might looks a good idea but VM will implicitly use new version when you upgrade qemu and can can break things. So rather upgrade machine manually after OS major upgrade.
To view current machine type of a VM:
$ virsh dumpxml | grep machine=
hvm
To edit:
$ virsh edit
# then look for machine= and set chosen version (i.e. "pc-q35-10.0") and restart
# the VM using virsh shutdown then virsh start (reboot wont work)
===== SSD/NVMe fstrim =====
View current disk definition in libvirt:
$ virsh dumpxml | grep -A2 '
You need **discard='unmap' detect_zeroes='unmap'** in **** so discard will propagate up to the host.
$ virsh edit
# look for and virsh start (reboot wont work)
Then in VM run:
$ fstrim -av
This will be done automatically by **fstrim.timer** service which should be enabled by default on recent debian. If not:
$ systemctl enable --now fstrim.timer
Created symlink '/etc/systemd/system/timers.target.wants/fstrim.timer' → '/usr/lib/systemd/system/fstrim.timer'.