Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using sparse raw image files for guest VMs and OCFS2 on the host (local-only, not clustered) for the reflink feature. I understand from Googling around that OCFS2 is one of the filesystems that can punch holes back into sparse files.

If I understand correctly, it may be possible (and apparently can be achieved with XFS) to combine this feature with TRIM/discard support in the guest machines so that when files in the guest are deleted, space on the host is automatically reclaimed. However despite much experimentation, I haven't been able to demonstrate this working.

Is this possible, and if it depends on versions of the kernel and/or QEMU, what are the minimum versions I need? Also have I missed anything with the configuration? I've:

  • mounted the (ext4) guest filesystem with the discard option in /etc/fstab
  • tried the current beta of Debian Wheezy for host and guest, and CentOS 6.2 for host
  • tried running fstrim on the guest (I get FITRIM ioctl failed: Operation not supported—but I'm not 100% sure if this is relevent)
  • tried bus=ide and bus=virtio (with CentOS 6.2 host)
share|improve this question
up vote 2 down vote accepted

You should be able to recover space by using virtio-scsi devices and specifying discard=unmap in the libvirt definition for the disk.

I haven't tried this in CentOS/RHEL but I did get this to work in later versions of Fedora. I wrote a blog post about it.

I would say to give it a try and see if it works.

share|improve this answer
I won't be able to test exactly as I've moved away from raw files (I'm using qed now), but thanks. – Jack Douglas Jul 25 '13 at 20:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.