By circumstance I’ve found out that the latest virtio drivers do not support trim or at least not ntfs optimizing.
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" cache="unsafe" discard="unmap"/>
<source file="/var/lib/libvirt/images/win11.qcow2" index="4"/>
<backingStore/>
<target dev="sda" bus="sata"/>
<alias name="sata0-0-0"/>
<address type="drive" controller="0" bus="0" target="0" unit="0"/>
</disk>
Optimize-Volume -DriverLetter C returns:
VERBOSE: Invoking retrim on (C:)...
VERBOSE: Retrim: 0% complete...
VERBOSE: Retrim: 100% complete.
VERBOSE: Performing pass 1:
VERBOSE: Retrim: 87% complete...
VERBOSE: Retrim: 100% complete.
VERBOSE:
Post Defragmentation Report:
VERBOSE:
Volume Information:
VERBOSE: Volume size = 62.95 GB
VERBOSE: Cluster size = 4 KB
VERBOSE: Used space = 28.37 GB
VERBOSE: Free space = 34.58 GB
VERBOSE:
Retrim:
VERBOSE: Backed allocations = 63
VERBOSE: Allocations trimmed = 4967
VERBOSE: Total space trimmed = 37.42 GB
But with:
<disk type="file" device="disk">
<driver name="qemu" type="qcow2" cache="unsafe" discard="unmap"/>
<source file="/var/lib/libvirt/images/win11.qcow2"/>
<target dev="vda" bus="virtio"/>
<address type="pci" domain="0x0000" bus="0x06" slot="0x00" function="0x0"/>
</disk>
(observe: the same image)
The command returns:
VERBOSE: Invoking slab consolidation on (C:)...
VERBOSE: Slab Analysis: 0% complete...
VERBOSE: Slab Analysis: 100% complete.
VERBOSE: Retrim: 0% complete...
VERBOSE:
Slab consolidation was skipped because there were few evictable slabs.
VERBOSE: Retrim: 100% complete.
Optimize-Volume : The operation failed with return code 40004
Activity ID: {eecd28dd-2d8e-0000-834f-cdee8e2ddd01}
At line:1 char:1
+ Optimize-Volume -DriveLetter C -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (StorageWMI:ROOT/Microsoft/...age/MSFT_Volume) [Optimize-Volume], CimExcep
tion
+ FullyQualifiedErrorId : StorageWMI 40004,Optimize-Volume
I wonder if there is documentation on the drivers? I use this as source