@@ -1871,6 +1871,9 @@ function vm_boot() {
18711871
18721872 # Add the disks
18731873 # - https://turlucode.com/qemu-disk-io-performance-comparison-native-or-threads-windows-10-version/
1874+ # Optimise disk I/O: enable TRIM/discard and zero detection for thin provisioning
1875+ DRIVE_OPTIMISATIONS=" discard=unmap,detect-zeroes=unmap"
1876+
18741877 if [[ " ${boot} " == * " efi" * ]]; then
18751878 QCOW2CODE=$( is_firmware_qcow2 " ${EFI_CODE} " )
18761879 QCOW2VARS=$( is_firmware_qcow2 " ${EFI_VARS} " )
@@ -1971,13 +1974,13 @@ function vm_boot() {
19711974
19721975 # shellcheck disable=SC2054,SC2206
19731976 args+=(-device ${MAC_DISK_DEV} ,drive=SystemDisk
1974- -drive id=SystemDisk,if=none,format=qcow2,file=" ${disk_img} " ${STATUS_QUO} )
1977+ -drive id=SystemDisk,if=none,format=qcow2,file=" ${disk_img} " , ${DRIVE_OPTIMISATIONS} ${STATUS_QUO} )
19751978 else
19761979 # Integrated mode: OpenCore is in the main disk's EFI partition
19771980 # Boot directly from the main disk
19781981 # shellcheck disable=SC2054,SC2206
19791982 args+=(-device ${MAC_DISK_DEV} ,drive=SystemDisk,bootindex=0
1980- -drive id=SystemDisk,if=none,format=qcow2,file=" ${disk_img} " ${STATUS_QUO} )
1983+ -drive id=SystemDisk,if=none,format=qcow2,file=" ${disk_img} " , ${DRIVE_OPTIMISATIONS} ${STATUS_QUO} )
19811984
19821985 if [ -n " ${img} " ]; then
19831986 # shellcheck disable=SC2054
@@ -1989,14 +1992,14 @@ function vm_boot() {
19891992 # shellcheck disable=SC2054,SC2206
19901993 args+=(-device ahci,id=ahci
19911994 -device ide-hd,bus=ahci.0,drive=SystemDisk
1992- -drive id=SystemDisk,if=none,format=qcow2,file=" ${disk_img} " ${STATUS_QUO} )
1995+ -drive id=SystemDisk,if=none,format=qcow2,file=" ${disk_img} " , ${DRIVE_OPTIMISATIONS} ${STATUS_QUO} )
19931996
19941997 elif [ " ${guest_os} " == " batocera" ] ; then
19951998 # shellcheck disable=SC2054,SC2206
19961999 args+=(-device virtio-blk-pci,drive=BootDisk
19972000 -drive id=BootDisk,if=none,format=raw,file=" ${img} "
19982001 -device virtio-blk-pci,drive=SystemDisk
1999- -drive id=SystemDisk,if=none,format=qcow2,file=" ${disk_img} " ${STATUS_QUO} )
2002+ -drive id=SystemDisk,if=none,format=qcow2,file=" ${disk_img} " , ${DRIVE_OPTIMISATIONS} ${STATUS_QUO} )
20002003
20012004 elif [ " ${guest_os} " == " reactos" ]; then
20022005 # https://reactos.org/wiki/QEMU
@@ -2006,18 +2009,18 @@ function vm_boot() {
20062009 elif [ " ${guest_os} " == " windows-server" ]; then
20072010 # shellcheck disable=SC2054,SC2206
20082011 args+=(-device ide-hd,drive=SystemDisk
2009- -drive id=SystemDisk,if=none,format=qcow2,file=" ${disk_img} " ${STATUS_QUO} )
2012+ -drive id=SystemDisk,if=none,format=qcow2,file=" ${disk_img} " , ${DRIVE_OPTIMISATIONS} ${STATUS_QUO} )
20102013
20112014 else
20122015 if [ " ${ARCH_VM} " == " aarch64" ]; then
20132016 # ARM64: bootindex=2 ensures disk boots after CD-ROM (bootindex=1) during installation
20142017 # shellcheck disable=SC2054,SC2206
20152018 args+=(-device virtio-blk-pci,drive=SystemDisk,bootindex=2
2016- -drive id=SystemDisk,if=none,format=${disk_format} ,file=" ${disk_img} " ${STATUS_QUO} )
2019+ -drive id=SystemDisk,if=none,format=${disk_format} ,file=" ${disk_img} " , ${DRIVE_OPTIMISATIONS} ${STATUS_QUO} )
20172020 else
20182021 # shellcheck disable=SC2054,SC2206
20192022 args+=(-device virtio-blk-pci,drive=SystemDisk
2020- -drive id=SystemDisk,if=none,format=${disk_format} ,file=" ${disk_img} " ${STATUS_QUO} )
2023+ -drive id=SystemDisk,if=none,format=${disk_format} ,file=" ${disk_img} " , ${DRIVE_OPTIMISATIONS} ${STATUS_QUO} )
20212024 fi
20222025 fi
20232026
0 commit comments