Skip to content

Instantly share code, notes, and snippets.

@johanmeiring
Created February 9, 2015 06:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johanmeiring/3d7c4c6187f7fd471d23 to your computer and use it in GitHub Desktop.
Save johanmeiring/3d7c4c6187f7fd471d23 to your computer and use it in GitHub Desktop.
VirtualBox Ubuntu VM creation from command line
#!/bin/bash
# Example file line:
# VM name,Group,MAC Address,RAM,Procs,HDD,VRDP port
# sf-mc-01,Group,080027EF99DD,512,1,6000,9007
if [[ ! -e $1 ]]; then
echo "File $1 not found."
exit 1
fi
while read line; do
echo $line | awk -F, '{print $1, $2, $3, $4, $5, $6, $7}' | while read name group mac ram cpu storage rdp; do
VBoxManage showvminfo ${name} > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
VBoxManage createvm --name ${name} --groups "/${group}" --ostype Ubuntu_64 --register
VBoxManage modifyvm ${name} --memory ${ram} --acpi on --boot1 disk --boot2 net --nic1 bridged --bridgeadapter1 eth0 --cpus ${cpu} --macaddress1 ${mac}
VBoxManage createhd --filename ${name}.vdi --size ${storage}
VBoxManage storagectl ${name} --name "Sata Controller" --add sata
VBoxManage storageattach ${name} --storagectl "Sata Controller" --port 0 --device 0 --type hdd --medium ${name}.vdi
VBoxManage modifyvm ${name} --vrdeport ${rdp} --vrde on
VBoxManage startvm ${name} --type headless
fi
done
#echo $line
done <$1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment