Decrease Virtualbox .vdi size by compressing it

A .vdi file (“VirtualBox Disk Image”) is at least a few gigabytes in size if you run a virtual Windows OS or Linux OS.

To reduce the filesize of this file, you can compress it. This can potentially save a few megabytes or even gigabytes on your disk. Maybe needless to say, but you want to close down this virtual OS first!

VboxManage modifyhd "E:\virtualbox\vdifiles\Ubuntu_x64.vdi" compact

You should replace the path with the path of your own .vdi file. This command will make your VirtualBox OS more compact.


Author Bio

Thank you for your interest in my blog! On this miniblog, I write mostly short (technical) blog posts that might interest other people. Read more about me or feel free to contact me.


2 thoughts on “Decrease Virtualbox .vdi size by compressing it

  1. Just a point, what is done is not “compress”, is “compact” or “shrink”.

    If something get compressed the physical data stored is changed (to a compress secuence of bytes) and some CPU is needed to un-compress.

    Compact and Shrink are very different, they reduce the size of the file (if some sectors inside the virtual disk partition are not needed), but do not “compress” any part of it.

    I am searching for a really good “on-the-fly” compress method for the vdi files… i know i can use Pismo File Mount to create a “holder” and activate compression on the .pfo file, also NTFS compression, but both get low copression ratio.

    Please think on the worst case for compression… Linux Ext4 host and Linux Ext4 guest filesystems… so no filesystem native compression, etc.

    Oracle, said that they will not add “compression on the fly” to the format since you can use native filesystem compression… well i told them “demostrate that” with a Linux host and a Linux guest Ext2 partitions… they stay in silent, but after a while still said the same, no future to include compression on the vdi.

    I had done some tests with Pismo File Mount (initial compression rate makes the .pfo be 50% of the vdi, since it use LZMA2, ata the cost of a 15% CPU increase), but since Pismo has no “shrink” method (other than create a new holder and move from one to another) it is not so good in practice… but that is really a compression… a 10GiB Windows 7 (with updates) VDI (after been compact by CloneVDI) fits in a 8GiB USB stick and free space on it is near 3GiB, the .pfo (a LZMA2 compressed file container that can be mounted Read+Write on the fly) only takes 5GiB (the 50% of the VDI).

    I do not know of any other cross-tool (Windows & Linux) that can “compress” with Read+Write on the fly on ANY filesystem… Pismo tool mounts a file like it it where a real folder, and is able to compress (really compress using LZMA2) and also encrypt, botth at same time and both on the fly.

    Please talk about “compressing” or change your post title to not cause confusion… compressin is not what you talked about when talking about VBoxManage … compact; it does not compress anything, it only reduce the file by not holding the non used space inside the partition… and by the way it really does it very bad… since all it does is really not store that sectors that are full fill with zeros… so if your non used space is not zeroed it does not get reduced at all… that is why CloneVDI comes on, it really analize guest filesystems to search for real non used sectors, no matter if they are or not zeroed, but again, that is compact or shrink, never can be called compress.

    Sorry me, i do not want to harm you, just clarify the difference between “compress” (change byte data to a reduced secuence that can be reverted back to the original one in a way that takes less space) versus “compact” or “shrink” (do not store innecesary parts), both concepts makes file smaller, but in a very different way.

Leave a Reply

Your email address will not be published. Required fields are marked *