Optimize QEMUKVM Virtio storage Driver error

Setup a Windows 1 box with disk drivers as virtio.

<disk type="file" device="disk">
  <driver name="qemu" type="qcow2" cache="writeback" discard="unmap"/>
  <source file="/var/lib/libvirt/images/win11-2.qcow2" index="2"/>
  <backingStore/>
  <target dev="vda" bus="virtio"/>
  <boot order="1"/>
  <alias name="virtio-disk0"/>
  <address type="pci" domain="0x0000" bus="0x06" slot="0x00" function="0x0"/>
</disk>

I have problems doing a Optimize in Windows:

"Defragmentierung" wird für "(C:)" aufgerufen...


Vor der Optimierung ausgeführter Bericht:

        Volumeinformationen:
                Volumegröße                 = 94.97 GB
                Freier Speicherplatz        = 43.37 GB
                Fragmentierter Speicherplatz insgesamt      = 7%
                Größter freier Speicherplatz     = 16.22 GB

        Hinweis: Dateifragmente, die größer als 64 MB sind, sind nicht in den Fragmentierungsstatistiken enthalten.
        Erneut optimieren:  übersprungen.

Datenfehler (CRC-Prüfung) (0x80070017)

If I connect this (to another win11 vm as second devices with SATA drivers) I can optimize without a problem. Is it possible that the virtio drivers are faulty? Installed what I think are the latest

I google translated the message into english and then did a web search for “windows defrag Data Error (CRC Check) (0x80070017)”.
There are a number of promising pages suggesting how to fix this error.

Is it possible you’re hitting this?

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

My AI of choice says:

  1. Download from: Making sure you're not a bot!
  2. Try version 0.1.240 or 0.1.229 (older versions sometimes work better)
  3. Or try the latest stable version (not the one from 2025)\

How about that…

Merging the new thread with the existing thread.
Thanks