Skip to content

Instantly share code, notes, and snippets.

@ryo1kato
Last active June 26, 2018 18:39
Show Gist options
  • Select an option

  • Save ryo1kato/8205791 to your computer and use it in GitHub Desktop.

Select an option

Save ryo1kato/8205791 to your computer and use it in GitHub Desktop.
clean cache and zerofill unused filesystem space for VirtualBox *.vdi image files
#!/bin/sh
#
# clean cache and zerofill unused filesystem space for VirtualBox *.vdi image files
#
set -ue
set -x
sudo apt-get clean
if ! type pv > /dev/null 2>&1
then
sudo apt-get install pv
fi
pv /dev/zero | sudo dd of=/zero || true
sudo rm -f /zero
set +x
echo 'Zero clear of the VM filesystem have done.
(1) Shutdown this VM.
(2) On HOST machine, run modifyhd --compact command like:
$ VBoxManage modifyhd DISK.vdi —compact'
@vidit2011998
Copy link

VBoxManage: error: Could not find file for the medium '/Users/viditgoyal/DISK.vdi' (VERR_FILE_NOT_FOUND)
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component MediumWrap, interface IMedium, callee nsISupports
VBoxManage: error: Context: "OpenMedium(Bstr(pszFilenameOrUuid).raw(), enmDevType, enmAccessMode, fForceNewUuidOnOpen, pMedium.asOutParam())" at line 179 of file VBoxManageDisk.cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment