Something Simple - Using What I Already Know
In Plain Text
echo Creating VM
$VBOX_CMD createvm --name $VM_NAME --ostype $VM_TYPE --register
echo Creating HD
$VBOX_CMD createhd --filename "$HD_FILE" --size $HD_SIZE
echo Adding IDE Controller
$VBOX_CMD storagectl $VM_NAME --name "IDE Controller" --add ide --controller PIIX4
echo Attaching HD
$VBOX_CMD storageattach $VM_NAME --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium "$HD_FILE"
echo Attaching DVD
$VBOX_CMD storageattach $VM_NAME --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium $INST_FILE
echo Setting RDP Port
$VBOX_CMD modifyvm $VM_NAME --vrdeport $RDP_PORT
echo Enabling RDP
$VBOX_CMD modifyvm $VM_NAME --vrde on
echo Setting Memory Size
$VBOX_CMD modifyvm $VM_NAME --memory $MEM_SIZE
echo Powering on VMBasically, I just took the steps from my previous post about headless VirtualBox and replaced the VM info with constants. Note that this script creates a VM with a 10GB hard drive and 128MB of RAM. That is fine for FreeBSD but if you create an Ubuntu Server VM you want at least 512MB of RAM or the installer may fail. Guess how I know...
$VBOX_CMD startvm $VM_NAME --type headless
Now if I want to roll out an Ubuntu VM I can just make sure I have the install ISO, edit a few constants at the top, run the script and the new VM is ready for installation and listening for a VRDE connection on port 3389.
You can get the above script with:
git clone https://github.com/kevinwilcox/vbox
When it runs, it looks a lot like this (notice I've changed the VM name from FBSDTemplate to OpenSecGeekScript):
Quick and easy!
A more sophisticated script has its appeal - it would be nice to run a command and have it prompt for the VM name, a selection from a list of supported OS types, the amount of RAM, the hard disk size and even the ISO to use for installation. Perfect is the enemy of the good and, in this case, this is good enough for me. Well, it's good enough for a first run!