Bioinformatics day-by-day

Menu

Shrink a dynamically growing disk from VirtualBox

I’m preparing Ubuntu image for the course. After installation of required software and datasets, the system image grew a lot. I have decided to shrink its size by disabling swap and removing unused data. But the system image didn’t shrink automatically after removal of the files. You need to do it manually:

Run your system from LiveCD

Install zerofree and free unused space

sudo apt-get install zerofree
# 10min
sudo zerofree -v /dev/sda1

In the host system, release and remove the image from VirtualBox (but keep it in the filesystem!)

And compact image size

VBoxManage modifyhd Ubuntu1404/Ubuntu1404.vdi --compact&lt;/code&gt;

Finally, you will have to add .vdi image back to VirtualBox machine.

In my case, the .vdi image shrunk from 7.2G to 6.2G (exactly the released size under Ubuntu), so I think it’s worth the effort.