VirtualBox useful tips

Change UUID

Got error like this

Cannot register the hard disk ... because a hard disk ... with UUID ... already exists.

Run this

cd "C:\Program Files (x86)\Sun xVM VirtualBox"
VBoxManage internalcommands sethduuid "C:VirtualBox VMs/MY VM/MY DISK.vdi"

Change dynamic disk size

cd "C:\Program Files (x86)\Sun xVM VirtualBox"
VBoxManage modifyhd "C:VirtualBox VMs/MY VM/MY DISK.vdi" --resize 16384

# Then maybe you have to use the GParted software to configure the disk

Run zerofree to reduce the disk size

Log into the Linux VM to delete all unnecessary files/folders
Install the zerofree on this Linux VM. Example for Ubuntu

sudo apt-get install zerofree

# Check the free disk
df -hl

Re-start the Linux VM and boot into recovery mode

Press ESC while the VM is starting then choose "Advanced options for Ubuntu", then "recovery mode", choose "root"

zerofree -v /dev/THE_SDA_OR_SDB_NAME

After above command finished, run this command on Windows

cd "C:\Program Files (x86)\Sun xVM VirtualBox"
VBoxManage modifyhd --compact "C:VirtualBox VMs/MY VM/MY DISK.vdi"

Loading