This is the first script I've ever written. It's not that pretty, it isn't overly user friendly, and I borrowed [stole] a lot of it from taz - http://forums.freebsd.org/showpost.php?p=194445&postcount=5
It is based on taz's script but allows me to quickly set up different VirtualBox VMs without having to edit the script:
I decided not to make it too fancy, requiring user to write full paths because the default machine directory may vary from machine to machine.
It is based on taz's script but allows me to quickly set up different VirtualBox VMs without having to edit the script:
Code:
#!/bin/sh
#-----------------------------------------------------------------------
#CONFIG
#-----------------------------------------------------------------------
echo "Type name of new VM:"
read vmName
echo "Type full path for new VM:"
read hdPath
echo "Type VM disk size in megabytes:"
read hdSize
echo "Type amount of RAM to use in megabytes:"
read ramSize
echo "Type amount of RAM for GPU to use in megabytes:"
read gpuRamSize
echo "Type VM OS Type:"
read osType
echo "Type full path to guest installtion media or ISO:"
read guestISO
echo "Type host network interface name:"
read nic
#create folder for virtual hard disk image
if [ ! -d $hdPath ]
then
mkdir $hdPath
fi
#-----------------------------------------------------------------------
#CREATE
#-----------------------------------------------------------------------
#create a new virtual hard disk image.
VBoxManage createhd --filename $hdPath/$vmName.vdi --size $hdSize
#create a new XML virtual machine definition file
VBoxManage createvm --name $vmName --ostype $osType --register
#add an IDE controller with a DVD drive attached, and the install ISO inserted into the drive. Set "--medium none" to detach all.
VBoxManage storagectl $vmName --name "IDE Controller" --add ide
VBoxManage storageattach $vmName --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium $hdPath/$vmName.vdi
VBoxManage storageattach $vmName --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium $guestISO
#set boot order
VBoxManage modifyvm $vmName --boot1 dvd --boot2 disk --boot3 none --boot4 none
#set I/O APIC support
VBoxManage modifyvm $vmName --ioapic on
#set the amount of RAM
VBoxManage modifyvm $vmName --memory $ramSize
#set the amount of RAM for virtual graphics card
VBoxManage modifyvm $vmName --vram $gpuRamSize
#set network mode(briged,NAT...)
VBoxManage modifyvm $vmName --nic1 bridged --bridgeadapter1 $nic
#enable USB support
VBoxManage modifyvm $vmName --usb on
#enable sound
VBoxManage modifyvm $vmName --audio oss --audiocontroller ac97
I decided not to make it too fancy, requiring user to write full paths because the default machine directory may vary from machine to machine.