Skip to content

Instantly share code, notes, and snippets.

@djravine
Last active March 6, 2020 05:57
Show Gist options
  • Save djravine/e4e225d96269cb0b887ecf4e2281bb74 to your computer and use it in GitHub Desktop.
Save djravine/e4e225d96269cb0b887ecf4e2281bb74 to your computer and use it in GitHub Desktop.
Create a new VirtualBox VM for Development
#!/bin/bash
set -o pipefail
# GIST: https://gist.github.com/djravine/e4e225d96269cb0b887ecf4e2281bb74
# USAGE: curl -sL https://gist.github.com/djravine/e4e225d96269cb0b887ecf4e2281bb74/raw | bash -s -- VMNAME USERNAME PASSWORD COUNTRY TIMEZONE LANGUAGE /PATH/TO/ISO "POST_INSTALL_COMMAND"
VMNAME="${1}"
OSUSERNAME="${2}"
OSPASSWORD="${3}"
OSCOUNTRY="${4}"
OSTIMEZONE="${5}"
OSLANGUAGE="${6}"
OSINSTALL="${7}"
POSTCOMMAND="${8}"
mkdir -p /development/vm/${VMNAME}
VBoxManage createvm --name ${VMNAME} --ostype Ubuntu_64 --register --basefolder /development/vm/${VMNAME}
VBoxManage modifyvm ${VMNAME} --cpus 2 --memory 5000 --vram 10 --boot1 dvd --boot2 disk --ioapic on --usb off --usbehci off --usbxhci off --audio none --natpf1 "SSH,tcp,127.0.0.1,2222,,22" --natpf1 "HTTP,tcp,127.0.0.1,8888,,80" --natpf1 "HTTPS,tcp,127.0.0.1,4433,,443"
VBoxManage setextradata ${VMNAME} GUI/SuppressMessages "all"
VBoxManage storagectl ${VMNAME} --name ${VMNAME}_SATA --add sata
VBoxManage createhd --filename /development/vm/${VMNAME}/${VMNAME}.vdi --size 30000 --format VDI --variant Standard
VBoxManage storageattach ${VMNAME} --storagectl ${VMNAME}_SATA --port 1 --type hdd --medium /development/vm/${VMNAME}/${VMNAME}.vdi
VBoxManage sharedfolder add ${VMNAME} -name development -hostpath /development
VBoxManage showvminfo ${VMNAME}
VBoxManage unattended install ${VMNAME} --user=${OSUSERNAME} --password=${OSPASSWORD} --country=${OSCOUNTRY} --time-zone=${OSTIMEZONE} --hostname=ubuntu.local --iso=${OSINSTALL} --language=${OSLANGUAGE} --start-vm=headless --install-additions
if [ ! -z "${POSTCOMMAND}" ]; then
echo "VBoxManage: info: Waiting for VM '${VMNAME}' to finish installing..."
VBoxManage guestproperty wait ${VMNAME} "/VirtualBox/GuestInfo/OS/NoLoggedInUsers"
echo "VBoxManage: info: VM '${VMNAME}' has successfully installed."
echo "$POSTCOMMAND"
eval "$POSTCOMMAND"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment