How to fix “fstrim: Operation not supported” under KVM?

February 6th, 2014

Maybe someone out there will have some ideas.

I have a KVM host running wheezy, with wheezy-backports versions of libvirt and qemu. I have defined a guest, properly set discard=unmap in the domain XML file for it, verified that’s being passed to the guest, but TRIM/DISCARD is just not working.

Mounting the ext4 filesystem with discard has no effect, and fstrim / always reports:

fstrim: /: FITRIM ioctl failed: Operation not supported

Every single time.

I’ve tried with the virtio, IDE, and SCSI (both default and virtio-scsi) backend drivers. The guest is also running wheezy (i386 version; the host is amd64) and I’ve tried the latest 3.12 backported kernel for it. No dice.

If I shut down the VM and mount the filesystem on the host, fstrim works fine.

Everything says this should work. But it doesn’t.

Any ideas?

Categories: Linux

Leave a comment

Comments Feed7 Comments

  1. planetdebian

    John Goerzen: How to fix “fstrim: Operation not supported” under KVM?: Maybe someone out there will have some … http://t.co/f6GT3zB3at

    Reply

  2. PlanetFeeds

    John Goerzen: How to fix “fstrim: Operation not supported” under KVM?: Maybe someone out there will have some … http://t.co/I2ulalKOcI

    Reply

  3. liquidskydesign

    John Goerzen: How to fix “fstrim: Operation not supported” under KVM? http://t.co/D8eugqIROW #debian #linux

    Reply

  4. John Goerzen

    I may have found part of the answer…

    virsh edit the domain. At the tag at the top, add xmlns:qemu=’http://libvirt.org/schemas/domain/qemu/1.0′

    Then, add lines like:

    qemu:commandline>
    qemu:arg value='-set'/>
    qemu:arg value='device.scsi0-0-0-0.discard_granularity=4096'/>
    qemu:arg value='-set'/>
    qemu:arg value='device.scsi0-0-1-0.discard_granularity=4096'/>
    /qemu:commandline>

    (adding appropriate characters to make it work)

    Reply

  5. SomeFeeds

    Planet Debian: John Goerzen: How to fix “fstrim: Operation not supported” under KVM? http://t.co/lPEkeJYJGU

    Reply

  6. Gunnar Wolf

    Umh, I think it will take a while before you can do this. TRIM is offered by specific hardware controllers, that is, by Flash-based media. What you see inside your KVM is an idealized block device, which can be backed on any kind of media — And to be able ot implement TRIM, KVM would have to be sure that the underlying structure also supports it :-(

    You could try doing a device pass-through, completely disregarding it from your host system… Although I really don’t know if there’s support for doing so.

    Reply

  7. Dino

    I’m running CentOS 6 and so far have been completely unsuccessful in getting KVM to pass the discard=’on’ option for the disk. I’ve upgraded qemu and libvirt to their latest versions from source, and even compiled a newer kernel (2.6.39.4). I’ll virsh edit the guest, insert discard=’on’ in the driver definition, save/quit, but the option doesn’t stick in the XML (I’ll virsh edit again and the edit I made is gone)

    Any ideas?

    Reply

Leave a comment

 

Feed

http://changelog.complete.org / How to fix “fstrim: Operation not supported” under KVM?