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 <vm> | grep machine= <type arch='x86_64' machine='pc-q35-3.1'>hvm</type>
To edit:
$ virsh edit <vm> # then look for machine= and set chosen version (i.e. "pc-q35-10.0") and restart # the VM using virsh shutdown <vm> then virsh start <vm> (reboot wont work)
View current disk definition in libvirt:
$ virsh dumpxml <vm> | grep -A2 '<driver' <driver name='qemu' type='raw' cache='none' io='native'/> <source dev='/dev/mapper/vg0-vm' index='1'/> <backingStore/>
You need discard='unmap' detect_zeroes='unmap' in <driver /> so discard will propagate up to the host.
$ virsh edit <vm> # look for <driver and add discard='unmap' detect_zeroes='unmap' and restart the VM # using virsh shutdown <vm> and virsh start <vm> (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'.