macOS: swap disk controller from virtio-blk-pci to ahci

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 `ahci` which does.

(We cannot use `virtio-scsi-pci` when running macOS, like we do in our default disk device,  because macOS does not support SCSI disks at all on x86_64 systems.)
pull/571/head
Dani Llewellyn 2 years ago committed by Martin Wimpress
parent fb8deb10e8
commit 881adb289a
  1. 17
      quickemu

@ -542,13 +542,13 @@ function vm_boot() {
case ${macos_release} in
catalina)
BALLOON=""
MAC_DISK_DEV="virtio-blk-pci"
MAC_DISK_DEV="ide-hd,bus=ahci.2"
NET_DEVICE="vmxnet3"
USB_HOST_PASSTHROUGH_CONTROLLER="usb-ehci"
;;
big-sur|monterey|ventura)
BALLOON="-device virtio-balloon"
MAC_DISK_DEV="virtio-blk-pci"
MAC_DISK_DEV="ide-hd,bus=ahci.2"
NET_DEVICE="virtio-net"
USB_HOST_PASSTHROUGH_CONTROLLER="nec-usb-xhci"
GUEST_TWEAKS="${GUEST_TWEAKS} -global nec-usb-xhci.msi=off"
@ -1071,18 +1071,19 @@ function vm_boot() {
if [ "${guest_os}" == "macos" ]; then
# shellcheck disable=SC2054
args+=(-device ahci,id=ahci
-device ide-hd,bus=ahci.0,drive=BootLoader,bootindex=0
-drive id=BootLoader,if=none,format=qcow2,file="${MAC_BOOTLOADER}")
-device ide-hd,bus=ahci.0,drive=BootLoader,bootindex=0,rotation_rate=1
-drive id=BootLoader,if=none,format=qcow2,discard=unmap,file="${MAC_BOOTLOADER}")
if [ -n "${img}" ]; then
# shellcheck disable=SC2054
args+=(-device ide-hd,bus=ahci.1,drive=RecoveryImage
-drive id=RecoveryImage,if=none,format=raw,file="${img}")
args+=(-device ide-hd,bus=ahci.1,drive=RecoveryImage,rotation_rate=1
-drive id=RecoveryImage,if=none,format=raw,discard=unmap,file="${img}")
fi
# shellcheck disable=SC2054,SC2206
args+=(-device ${MAC_DISK_DEV},drive=SystemDisk
-drive id=SystemDisk,if=none,format=qcow2,file="${disk_img}" ${STATUS_QUO})
args+=(-device ${MAC_DISK_DEV},drive=SystemDisk,rotation_rate=1
-drive id=SystemDisk,if=none,format=qcow2,discard=unmap,file="${disk_img}" ${STATUS_QUO})
elif [ "${guest_os}" == "kolibrios" ]; then
# shellcheck disable=SC2054,SC2206
args+=(-device ahci,id=ahci

Loading…
Cancel
Save