Last active
March 20, 2018 02:58
-
-
Save tannerdsilva/2e199e48624121c170f11720c48f9e8e to your computer and use it in GitHub Desktop.
Creates a VirtualBox VM with the given name and installer ISO.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
base="/path/to/vm/directory" | |
bridge_interface="eno2" # network interface to bridge the VM to | |
diskMB=50000 | |
# a few sanity checks | |
if [ -z "$1" ]; then | |
echo "usage: makevm.sh <vm name> <path for installer ISO file>" | |
exit 1 | |
fi | |
if ! [ -e "$2" ]; then | |
echo "usage: makevm.sh <vm name> <path for installer ISO>" | |
exit 1 | |
fi | |
#expand relative paths | |
ospath="$(readlink -f "$2")" | |
# make the vm. pretty straightforward | |
vboxmanage createvm --name $1 --basefolder $base --register | |
cd "$base/$1" | |
vboxmanage createmedium disk --filename boot.vdi --size $diskMB --format vdi | |
# attach storage | |
vboxmanage storagectl $1 --name idec --add ide | |
vboxmanage storagectl $1 --name satac --add sata --hostiocache on | |
vboxmanage storageattach $1 --storagectl idec --port 0 --device 0 --type dvddrive --medium "$ospath" | |
vboxmanage storageattach $1 --storagectl satac --port 0 --device 0 --type hdd --medium boot.vdi | |
printf "VM $1 created, please enter a VRDE port to connect to the VM's video output. The VM will boot after this step.\n\nvrde port: " | |
read -r port | |
printf "how many megabytes of memory should this vm have?\nmegabytes: " | |
read -r mb | |
vboxmanage list ostypes | |
printf "\nwhat is the os type of this vm?" | |
read -r os | |
##set port and a few other misc configurations | |
vboxmanage modifyvm $1 --memory $mb --nic1 bridged --ioapic on --bridgeadapter1 $bridge_interface --cableconnected1 on --vrde on --vrdeport $port --boot1 dvd --boot2 disk --audio none --usb off --usbehci on --usbxhci on | |
vboxmanage modifyvm $1 --ostype $os | |
##start vm | |
if [ $? -eq 0 ]; then | |
vboxheadless -s $1 | |
else | |
echo "there was an error modifying the vm properties. please delete this vm and try again" | |
fi | |
vboxmanage modifyvm $1 --boot1 disk --boot2 dvd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment