-
-
Save develpudu/9f75084fd1cf1cb3e2c4438ef87d2c3d to your computer and use it in GitHub Desktop.
VirtualBox Ubuntu VM creation from command line
This file contains hidden or 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 | |
| # 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