From fb8deb10e8dab766696c173fd10a58d0749841ab Mon Sep 17 00:00:00 2001 From: Dani Llewellyn Date: Mon, 17 Oct 2022 20:22:46 +0100 Subject: [PATCH] Defaults: Switch default disk from virtio-blk-pci to virtio-scsi-pci Currently, the virtio specification does not include provision for the TRIM (aka DISCARD) command that allows a guest operating system to signal the disk hardware that blocks have become unused so that the underlying device may clear the physical data. The TRIM/DISCARD command was introduced for SSD disks as an extension to the AHCI specification that is used in SATA systems. With Virtual Machines we can use this command to tell QEMU's Qcow2 driver to reclaim unused space in the disk image. This ensures the disk image file is kept to the smallest size possible where without the TRIM/DISCARD command it grows to it's maximum configured size and never shrinks again when data is deleted. Let's swap our default disk driver from `virtio-blk-pci` which does not support TRIM to `virtio-scsi-pci` which does. --- quickemu | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/quickemu b/quickemu index 52ac41b..0b7386e 100755 --- a/quickemu +++ b/quickemu @@ -1103,8 +1103,9 @@ function vm_boot() { else # shellcheck disable=SC2054,SC2206 - args+=(-device virtio-blk-pci,drive=SystemDisk - -drive id=SystemDisk,if=none,format=qcow2,file="${disk_img}" ${STATUS_QUO}) + args+=(-device virtio-scsi-pci,id=scsi0 + -device scsi-hd,drive=SystemDisk,bus=scsi0.0,lun=0,rotation_rate=1 + -drive id=SystemDisk,if=none,format=qcow2,discard=unmap,file="${disk_img}" ${STATUS_QUO}) fi # https://wiki.qemu.org/Documentation/9psetup