Virtual Disk Image (
VDI) files grow over time. If You discover that VDI on the host system is much bigger than used space on the guest partition it is time for compaction.
- Install zerofree tool (
apt-get install zerofree).
- Remove unused files (
- Reboot the guest system in single user mode (Grub menu will appear if you press and hold
Shiftduring starting, then hit
ewhen Grub boot appear and append
singleoption to the Grub boot parameters).
- Remount filesystems as readonly (
mount -n -o remount,ro -t auto /dev/sda1 /).
- Fill unused block with zeros (
zerofree /dev/sda1). It’s time consuming operation. If You have other disk devices (e.g.
/dev/sda5) then also perform
zerofreeon each one.
- Shutdown the system (
- Compact VDI files on the host system (
VBoxManage modifyhd my.vdi compact). It’s time consuming operation.
Instead points 1,3-5 to fill free space with zeros You can do following (You don’t need to boot in single user mode)
sudo dd if=/dev/zero of=/bigemptyfile bs=4096k
sudo rm -rf /bigemptyfile