=== modified file 'testdrive' --- testdrive 2009-12-14 04:39:23 +0000 +++ testdrive 2009-12-17 17:17:26 +0000 @@ -161,25 +161,67 @@ kvm -m $MEM -cdrom $PATH_TO_ISO -drive file=$DISK_FILE,if=virtio,index=0,boot=on $KVM_ARGS ;; virtualbox) - echo - echo "INFO: Creating disk image..." + # Determine which version of VirtualBox we have installed. What is returned is + # typically a string such as '3.1.0r55467', lets assume that the command line + # is consistent within 3.0.x versions and 3.1.x version so extract this part of the + # version string for comparison later + vboxversion=$(VBoxManage --version) + vboxversion=${vboxversion%.*} + echo "INFO: VirtualBox $vboxversion detected." + DISK_SIZE=$(echo "$DISK_SIZE" | sed "s/G$/000/") rm -f $DISK_FILE sed -i "\:HardDisk.*$DISK_FILE:d" $HOME/.VirtualBox/VirtualBox.xml - VBoxManage createhd --filename $DISK_FILE --size $DISK_SIZE - VBoxManage modifyvm $VBOX_NAME --hda none >/dev/null || true - VBoxManage unregistervm $VBOX_NAME --delete >/dev/null || true - rm -f $HOME/.VirtualBox/Machines/$VBOX_NAME/$VBOX_NAME.xml - echo - echo "INFO: Running the Virtual Machine..." - VBoxManage createvm --register --name $VBOX_NAME - VBoxManage modifyvm $VBOX_NAME --memory $MEM - VBoxManage modifyvm $VBOX_NAME --hda $DISK_FILE - VBoxManage modifyvm $VBOX_NAME --boot1 disk - VBoxManage modifyvm $VBOX_NAME --boot2 dvd - VBoxManage modifyvm $VBOX_NAME --nic1 nat - VBoxManage startvm $VBOX_NAME - VBoxManage controlvm $VBOX_NAME dvdattach $PATH_TO_ISO + + if [ "$vboxversion" = "3.0" ] + then + # Below are the command to create the VM in VirtualBox 3.0.x + echo + echo "INFO: Creating disk image..." + VBoxManage createhd --filename $DISK_FILE --size $DISK_SIZE + VBoxManage modifyvm $VBOX_NAME --hda none >/dev/null || true + rm -f $HOME/.VirtualBox/Machines/$VBOX_NAME/$VBOX_NAME.xml + echo + echo "INFO: Running the Virtual Machine..." + VBoxManage createvm --register --name $VBOX_NAME + VBoxManage modifyvm $VBOX_NAME --memory $MEM + VBoxManage modifyvm $VBOX_NAME --hda $DISK_FILE + VBoxManage modifyvm $VBOX_NAME --ostype Ubuntu + VBoxManage modifyvm $VBOX_NAME --vram 128 + VBoxManage modifyvm $VBOX_NAME --boot1 disk + VBoxManage modifyvm $VBOX_NAME --boot2 dvd + VBoxManage modifyvm $VBOX_NAME --nic1 nat + VBoxManage startvm $VBOX_NAME + VBoxManage controlvm $VBOX_NAME dvdattach $PATH_TO_ISO + elif [ "$vboxversion" = "3.1" ] + then + # Below are the commands to create the VM in VirtualBox 3.1.x + echo + echo "INFO: Creating disk image..." + VBoxManage createhd --filename $DISK_FILE --size $DISK_SIZE + VBoxManage storageattach testdrive --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium none >/dev/null || true + VBoxManage storageattach testdrive --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium none >/dev/null || true + VBoxManage unregistervm $VBOX_NAME --delete >/dev/null || true + echo + echo "INFO: Running the Virtual Machine..." + VBoxManage createvm --register --name $VBOX_NAME + VBoxManage modifyvm $VBOX_NAME --memory $MEM + VBoxManage storagectl $VBOX_NAME --name "IDE Controller" --add ide + VBoxManage storageattach $VBOX_NAME --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium $DISK_FILE + VBoxManage storageattach $VBOX_NAME --storagectl "IDE Controller" --port 0 --device 1 --type dvddrive --medium $PATH_TO_ISO + platform=$(echo $ISO_URL | grep -qs amd64 && echo Ubuntu_64 || echo Ubuntu) + VBoxManage modifyvm $VBOX_NAME --ostype $platform + VBoxManage modifyvm $VBOX_NAME --vram 128 + VBoxManage modifyvm $VBOX_NAME --boot1 disk + VBoxManage modifyvm $VBOX_NAME --boot2 dvd + VBoxManage modifyvm $VBOX_NAME --nic1 nat + VBoxManage startvm $VBOX_NAME + else + echo + echo "INFO: Unsupported version of VirtualBox installed, pleast install v3.0 or v3.1." + exit + fi + # Loop as long as this VM is running while true; do sleep 2