Skip to content

Instantly share code, notes, and snippets.

@jgcasta
Created June 14, 2014 10:59
Show Gist options
  • Save jgcasta/641d7bfede84886e5a8d to your computer and use it in GitHub Desktop.
Save jgcasta/641d7bfede84886e5a8d to your computer and use it in GitHub Desktop.
Change memory size for a running Virtual Box virtual machine
#!/bin/bash
#
# ChangeVBMem.sh
#
# ver 1.0
#
# Jose Gomez Castaño jgcasta@gmail.com
#
# Change memory size for a running virtual machine. The system will be stopped and restarted
# In this version, all data has to be saved before
#
# nameVB: Virtual Machine name
# newSize: RAM size in MB
#
# Usage: $./ChangeVBMem.sh nameVB newSize
#
name=$1
newSize=$2
totalMem=$(free | awk '/^Mem:/{print $2}')
totalMemM=$((totalMem/1000))
if [ $totalMemM -lt $newSize ];then
echo "ERROR: The maximum memory size of your physical machine is "$totalMemM" Mb and you are choosing "$newSize" Mb, please choose a lower value for the virtual machine"
exit 0
fi
VBoxManage controlvm $name poweroff
VBoxManage modifyvm $name --memory $newSize
VBoxManage startvm $name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment