1
1
I have seen it with both VBox native VDI format and VMDK format. Even though I delete files from virtual drive, I see it always keeps growing. I have some vague idea that file zero-ing doesn't happen with the virtual drives from this link. When I tried to do that with SDelete (as said in the link) it didn't reduce the VDi disk size. I have applications which once installation grows the disk to 10GB each time. I believe there should be some simple way to zero it than going through the tedious process, is there any? Is there any option in VirtualBox to keep virtual drive small?
after zeroing the clusters you have to run
vboxmanage --compactto remove those zero clusters out of the vdi file – phuclv – 2017-06-09T03:31:41.697Does Vbox reuse the zero-ed clusters at any point after consuming it?
Should I have to do that manually? Why VBox doesn't do that automatically as windows or mac does on the hdd? – Ajayvignesh – 2017-06-09T03:39:53.567
2Sparce image files—which is what VirtualBox disk images are—start off with only the bare minimum needed for the system and grow as needed and by use. So let’s say a clean VirtualBox setup starts with an 8GB disk, but only 1GB is used, then the file size would be 1GB. Add a 2GB pile of files to that 1GB system and now it’s 3GB. But remove the 2GB and you still will have the file size of the disk image itself be 3GB. – JakeGould – 2017-06-09T04:06:34.697
because harddrives are fixed-sized. If you created a fixed-sized vdi you also don't need to shrink the image, but then it cost you a lot of disk space. Do you want a 1TB file for an empty 1TB drive? Normally vdi and vmdk files are dynamically resized so that if you don't store anything in the disk you don't have to waste space for that. It just stores non-zero clusters – phuclv – 2017-06-09T04:33:59.467
theoretically it's possible to use SSD TRIM commands to automatically compact the removed blocks although it seems none of the current hypervisors implement that
– phuclv – 2017-06-09T05:33:34.890Just to add info on what i have tried. I built a VM with 10GB dynamic disk and filled it up till 10GB. Beyond 10GB, the disk didn't grow beyond 10GB, and deleting and adding new files in the disk is still possible after reaching 10GB of .vdi file.
One more thing I noticed when I snapshot after reaching 10GB, deleting and adding file did grew the snapshot to some 1.8GB and it maxed at 1.8GB. Still allowed me to delete and add more files in snapshot too.
Hence, i decided to leave it with dynamic drive for my VMs which will eventually stop growing after my disk size mentioned. – Ajayvignesh – 2017-06-11T03:52:28.633