Skip to content

Instantly share code, notes, and snippets.

@jjasghar
Created May 18, 2012 19:44
Show Gist options
  • Save jjasghar/2727267 to your computer and use it in GitHub Desktop.
Save jjasghar/2727267 to your computer and use it in GitHub Desktop.
Using Virtualbox to build throw away vms
#!/usr/local/bin/bash
VDI_DIR='/home/me/vdi/'
UBUNTU_GOLD_VDI="ubuntu_11_10_gold.vdi"
REDHAT_GOLD_VDI="centos_6_2_gold.vdi"
HOST_NIC="em0"
echo "Name of VM"
read name_of_vm
echo "OS type (Ubuntu, Redhat_64)"
read ostype
cd $VDI_DIR
if [ "$ostype" = "Ubuntu" ]; then
echo "Cloning Ubuntu vdi"
VBoxManage clonehd $UBUNTU_GOLD_VDI ubuntu_11_10_$name_of_vm.vdi
elif [ "$ostype" = "Redhat_64" ]; then
echo "Cloning Redhat vdi"
VBoxManage clonehd $REDHAT_GOLD_VDI centos_6_2_$name_of_vm.vdi
else
clear;
echo "something broke"
fi
VBoxManage createvm --name "$name_of_vm" --ostype "$ostype" -register
echo "Adding 4gigs of memory"
VBoxManage modifyvm "$name_of_vm" --memory 4096 --boot1 dvd
echo "Adding the storage ide controller"
VBoxManage storagectl "$name_of_vm" --name "IDE Controller" --add ide
echo "Attaching vdi to storage controller"
if [ "$ostype" = "Ubuntu" ]; then
VBoxManage storageattach "$name_of_vm" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium ubuntu_11_10_$name_of_vm.vdi
fi
if [ "$ostype" = "Redhat_64" ]; then
VBoxManage storageattach "$name_of_vm" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium centos_6_2_$name_of_vm.vdi
fi
echo "Adding NIC and making it a bridge adapter"
VBoxManage modifyvm "$name_of_vm" --nic1 bridged --nictype1 82543GC --bridgeadapter1 $HOST_NIC
clear
echo ""
echo ""
echo ""
echo "Starting it in headless mode have fun!"
echo ""
echo ""
echo "Check the NIC, it could change and you'll have to edit it via the console, hence the VNC connection here in a sec"
echo ""
echo ""
VBoxHeadless -s "$name_of_vm" -n
cd $HOME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment