9

I have been mostly using fixed-sized disk images for Oracle virtualbox, but I am considering switching to dynamic disk images as I heard that dynamic images are similar in performance to fixed-size images except when expanding.

One operation I do a lot though is to zero-fill a fixed-size disk image before backing it up using a zip program (to reduce the size of the zip archive). My question is, when I zero-fill a dynamic disk, will the disk size increase to its maximum declared value? (For my specific case, I am using sdelete -z on windows partitions.)

One additional question is, is there a way to zero-fill partitions without increasing the disk size?

Thanks.

-- EDIT --

To clarify, the reason I ask is that I want to keep the size of compressed virtualbox images at a minimum. Zero-filling a fixed sized image does the job as the zero-filled portion contributes almost nothing to the compressed image. However, if I switch to dynamic disk, zero-filling seems to defeat the purpose of using dynamically sized images.

The second part of my question is really asking if there is a better alternative than zero-filling that can remove unused sectors without expanding the disk size.

  • 1
    yes, a fully allocated dynamically-allocating disk, will be its fully allocated size. I'm not quite sure what the confusion is here, nor can I concieve of a reason to do what you describe, but no, you can't stuff a bunch of data (albeit all 0's) into a file and not expect its size to change. – Frank Thomas Apr 28 '15 at 16:53
  • @FrankThomas Please see my update for the reason to do zero-filling. – tinlyx Apr 28 '15 at 17:04
  • 1
    @tinlyx I just answered and it seems I answered your edit in my answer as well, you can actually compact the dynamic disk images using virtualbox tools. So a zerofill followed by a compact would make a perfect image for archival purposes. – Mokubai Apr 28 '15 at 17:11
11

I have just tested it (using sdelete -z in a VM) and zero filling the disk will not appreciably increase the size of the dynamic disk image. Virtualbox is smart enough to recognise that when you are writing zeros to an already empty block the disk does not need to have the block written again.

But even if it did then that's not too bad, because zero filling the disk will also do is allow you to compact it again using the Virtualbox Tools in your host: How to compact VirtualBox's VDI file size?

When I zero filled my VM it took the image size up from ~14.5GB to ~15.5GB but did not completely allocate all the disk space, which would have been approximately 48GB.

In fact zero filling the disk (via sdelete -z) will allow you to properly free up any space that was written but has since been freed up by your VM operating system, then you can run the command VBoxManage.exe modifyhd c:\path\to\thedisk.vdi --compact on your host machine to properly compact the dynamic disk image back down to its minimum size.

  • thanks. Indeed, sdelete -z does not increase dynamic disk size much. – tinlyx Apr 28 '15 at 22:11

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.