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 (
apt-get autoremove
,apt-get autoclean
,orphaner --guess-all
). - Reboot the guest system in single user mode (Grub menu will appear if you press and hold
Shift
during starting, then hite
when Grub boot appear and appendsingle
option 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 performzerofree
on each one. - Shutdown the system (
poweroff
). - 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