1

This feature would slow down file removal on native OS for no reason, however is particulary useful to compact virtual machine images. Some formats like VirtualBox' .vdi allows not only to grow dynamically based on space allocation after creation of the image file, but also to replace blocks which exclusively consist of zeros with references which shrinks the image to a minimal size which is only slightly larger than the space actually occupied by the guest OS.

Since the guest OS doesn't and shouldn't know that it's running in a virtual machine it leaves deallocated blocks filled with unused non-zeroed bytes. This can cause a large number of blocks to be allocated in the image file, but not by the guest OS's filesystem which represents a large bulk of unnecessary data contained in one single file.

One has to use tools like zerofree for ext2/3/4 or other ways which fills up the image file once completely before the compacting by detection of zero-blocks can take place on the host. If the host system doesn't support in-band deduplication this is very troublesome. And the VM eventually can't be used for some time up to hours because the zero-ing requires exclusive or read-only access to the data.

It's possible to compact a VM image file without running commands inside the VM by reducing blocks or extents which contain only 0s because they've never been touched or became all 0 for other non-systematical (and improbable) reasons. I'm looking for a maximization of the effect. And, of course, the storage needs for VM images can be reduced by means of deduplication which is however a different thing.

0
  1. To do such operation (shrink disk) you need to have empty blocks/sectors on the end of the disk so you should defrag the filesystem.
  2. Also you cant expect VM software know all possible filesystems. So you need to shrink your filesystem also (require point 1)
  3. And at the end you should shrink your partition(s) to free disk space on the end of virtual disk (need point 1 and 2)

For me this is the way to reduce VM virtual disks

  • My intention is to punch holes in the file system. While shrinking the filesystem can lead to blocks or extents being abondoned by the filesystem on the guest they still need to be zeroed in order to be able to punch the hole on the host system because that's where the space is consumed. I don't understand what the VM software understanding filesystems has to do with that. The VM software is agnostic of the filesystem in the guest because that's a guest OS task and of the host because it only stores (large) files there. – Karl Richter Jan 10 at 11:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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