Compact VirtualBox VM .vdi Disk Size
#VirtualBox #VDI #Compact
Full steps can be found at https://i12bretro.github.io/tutorials/0395.html
NOTE: This process only works on dynamically allocated virtual disks. If you're not sure, launch VirtualBox and go to File ≫ Virtual Media Manager. Select the virtual drive and view the properties
Create backups of virtual disks before attempting these steps
--------------------------------------------------------------------
Compacting Windows Guest VM
--------------------------------------------------------------------
01. Launch the Windows VM
02. Inside the VM, launch a web browser and download the sdelete utility https://technet.microsoft.com/en-us/sysinternals/bb897443
03. Extract the downloaded sdelete .zip file
04. Copy sdelete.exe for 32-bit OS or sdelete64.exe for 64-bit OS to the C:\Windows directory
05. Launch Command Prompt by right clicking the Start button ≫ Run ≫ type cmd ≫ Press Enter
06. Run the following command to zero out the free space on the disk, replace the drive letter to target additional drives
sdelete64.exe c: -z
07. Once the process completes, shutdown the VM
--------------------------------------------------------------------
Compacting Linux Guest VM
--------------------------------------------------------------------
01. Download the SystemRescue live disc https://www.system-rescue.org/Download/
02. Launch VirtualBox Manager
03. Right click the VM to be compacted ≫ Settings
04. Select Storage on the left hand side
05. Select the optical disc drive
06. Click the disk selection icon ≫ Choose a disk file...
07. Navigate to the downloaded SystemRescue .iso file
08. Click Open and OK to close the settings
09. Right click the VM ≫ Start ≫ Normal Start
10. Press Enter to boot SystemRescue using default options
11. Once SystemRescue has finished booting, run the following commands
# list the attached disks
fdisk -l
# find the disk to be compacted
# usually listed as /dev/mapper/....
# run the following, replacing the drive identifier as needed
zerofree -v /dev/mapper/
# after zerofree completes, shutdown the VM
shutdown now
12. Go back into the VM settings and remove the attached SystemRescue .iso
--------------------------------------------------------------------
Compacting the Virtual Disk
--------------------------------------------------------------------
01. Launch VirtualBox Manager on the host device
02. Right click the VM to be compacted ≫ Show in Explorer
03. Right click in the white space ≫ Open PowerShell window here...
04. Run the following command, replacing the file name of the virtual disk
"%programfiles%\Oracle\VirtualBox\vboxmanage.exe" modifymedium disk "name_of_disk.vdi" --compact
### Connect with me and others ###
★ Discord: https://discord.com/invite/EzenvmSHW8
★ Reddit: https://reddit.com/r/i12bretro
★ Twitter: https://twitter.com/i12bretro