Compress Ubuntu Disk Space in Parallels or VirtualBox

If you have setup your parallels as an expanding disk, which might perform a little less but our solid state drives can handles this. You can delete your snapshot and fill all of your deleted space with zeros. This allows the reclaim disk feature of parallels to work. I was able to recover about 20GB of disk space. My 65GB hard drive was taking 75GB of space due to snapshot.

Windows Tool

SDelete (Local Copy) SDelete.zip
https://technet.microsoft.com/en-us/sysinternals/bb897443 (Original Location)

sdelete.exe c: -z

Linux Tool

Then go into sudo and run the sfill command, let it run and you will get a warning about being out of space, but it will be okay.

sudo apt-get install secure-delete
sudo su -
sfill -l -l -z -v /

VirtualBox Compression

VBoxManage list hdds

VBoxManage modifymedium disk "/home/mruckman/VirtualBox VMs/Windows10/Windows10 Clone.vdi" --compact

VBoxManage modifymedium disk "/home/mruckman/VirtualBox VMs/Ubuntu 22.04/Ubuntu 22.04.vdi" --compact

VBoxManage modifymedium disk "/home/mruckman/VirtualBox VMs/Ubuntu 22.04 Docker/Ubuntu 22.04 Docker Machine.vdi" --compact

Windows

You need to open a command prompt and NOT a PowerShell terminal

"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd "C:\Users\mruckman\VirtualBox VMs\Ubuntu 22.04\Ubuntu 22.04.vdi" --compact
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" modifyhd "C:\Users\mruckman\VirtualBox VMs\Ubuntu 22.04 Docker\Ubuntu 22-disk001.vdi" --compact

After you're done, take a new snapshot.

You can try this method instead, it does not require any additional installation:

Refer: https://forum.parallels.com/threads/tip-how-to-compact-your-virtual-disks-when-using-linux-guests.29829/

$ dd if=/dev/zero of=deleteme bs=1M

Virtual Box is a bit different OLDER Deprecated

Refer: http://splatoperator.com/2012/07/compacting-a-vmdk-virtual-machine-disk-format-image/

Zero out the free space
Clone the VMDK
Attach new drive

$ VBoxManage clonehd $disk_name.vmdk clone.vmdk

$ /usr/local/bin/vboxmanage clonehd "/Users/mauriceruckman/VirtualBox VMs/Ubuntu-14.04-HAL-UI-35GB/Ubuntu-14.04-HAL-UI-35GB-disk1.vmdk" "/Users/mauriceruckman/VirtualBox VMs/Ubuntu-14.04-HAL-UI-35GB/Ubuntu-14.04-HAL-UI-35GB-20160812-disk1.vmdk"