image_opts="-cdrom $image"
else
image_opts="-drive file=$image,if=$drive_interface"
+
+ # TRIM support
+ if [ "$image_discards" != "n" ]; then
+ image_opts="$image_opts,discard=unmap"
+ fi
fi
if [ ! -z "$virtio_rng" ]; then
# Image type: file or device (kvmx-create only)
image_type="file"
+# Discards support
+# See https://jschumacher.info/2020/11/debian-qemu-libvirt-qcow2-and-fstrim/
+# https://chrisirwin.ca/posts/discard-with-kvm-2020/
+image_discards="y"
+
# Image size
size="10G"
# Fstrim
# See https://pve.proxmox.com/wiki/Shrink_Qcow2_Disk_Files
+# See also image_discards kvmxfile option
+sudo systemctl enable fstrim.timer
+sudo systemctl start fstrim.timer
sudo fstrim -av
sudo sync