Custom Batch file to launch VM
Posted: 22. May 2014, 22:57
***UPDATE***
SOLVED!! See my last post for details.
Hey all,
Forgive me if I'm posting in the wrong area.
I am attempting to write a batch script that does the following:
1. Check for Vbox installation
2. Check if appliance has already been installed - Import if not found (appliance stored remotely)
3. Check for the vmdk's - if not found, attach them (stored remotely) otherwise goto Step 4.
4. Start the VM
Now, I have a working script that I wrote today but it does not execute Step 3 from the above list.
For further background: The idea here is to have an immutable vmdk as this will be an on-demand development machine for a large team of devs. Simply a place for them to quickly bring up an environment and check their code. Hence the immutable vmdk.
What my current script does is when it finds an already installed instance of the Guest VM, it still attempts to attach the storage, so my Virtual Media Manager is getting filled up with tons of parent and child snapshots (I'm using the --setuuid "" command in my script to generate a new random uuid on each launch).
I understand that the setuuid parameter is my main problem and I'd rather not use that. but I don't know how to check to see if the users local install of VBox has the correct storage attached already.
Here is the first revision of the script I wrote today:
Again, when there is no storage attached and no VM already created, this script works like a dream. It's launching it a 2nd, 3rd, 4th, etc. time that issues arise.
I hope I've explained this well enough.
Any help is greatly appreciated!
SOLVED!! See my last post for details.
Hey all,
Forgive me if I'm posting in the wrong area.
I am attempting to write a batch script that does the following:
1. Check for Vbox installation
2. Check if appliance has already been installed - Import if not found (appliance stored remotely)
3. Check for the vmdk's - if not found, attach them (stored remotely) otherwise goto Step 4.
4. Start the VM
Now, I have a working script that I wrote today but it does not execute Step 3 from the above list.
For further background: The idea here is to have an immutable vmdk as this will be an on-demand development machine for a large team of devs. Simply a place for them to quickly bring up an environment and check their code. Hence the immutable vmdk.
What my current script does is when it finds an already installed instance of the Guest VM, it still attempts to attach the storage, so my Virtual Media Manager is getting filled up with tons of parent and child snapshots (I'm using the --setuuid "" command in my script to generate a new random uuid on each launch).
I understand that the setuuid parameter is my main problem and I'd rather not use that. but I don't know how to check to see if the users local install of VBox has the correct storage attached already.
Here is the first revision of the script I wrote today:
Code: Select all
@echo off
Title Configure VBox and launch VM
REM Script to configure and launch a VM with remote storage.
:START
echo Checking for virtual Box...
IF EXIST C:\progra~1\Oracle\VirtualBox\VirtualBox.exe goto STARTCONFIG
goto VBOXERROR
:STARTCONFIG
echo Starting vbox Import...
CD C:\progra~1\Oracle\VirtualBox\
IF EXIST C:\Users\%USERNAME%\Virtua~2\JavaTesting\JavaTesting.vbox goto SKIPCONFIG
echo.
echo.
echo VM Not Found. Beginning import...
echo.
echo.
pause
REM Import the appliance and attach the storage to it.
vboxmanage import \\w7-2ua22514sf\VMTesting\JavaTest1.ova --vsys 0 --vmname JavaTesting --memory 2048
vboxmanage storageattach JavaTesting --storagectl "SATA Controller" --port 0 --type hdd --medium \\w7-2ua22514sf\VMTesting\JavaTestingDisk1.vmdk --mtype immutable --setuuid ""
vboxmanage storageattach JavaTesting --storagectl "SATA Controller" --port 1 --type hdd --medium \\w7-2ua22514sf\VMTesting\JavaTestingDisk2.vmdk --mtype immutable --setuuid ""
vboxmanage startvm JavaTesting
goto END
:SKIPCONFIG
cls
REM Found the VM. Attach the storage. (I need to check for storage first..How to?)
echo VM already exists. Starting Storage Configuration...
vboxmanage storageattach JavaTesting --storagectl "SATA Controller" --port 0 --type hdd --medium \\w7-2ua22514sf\VMTesting\JavaTestingDisk1.vmdk --mtype immutable --setuuid ""
vboxmanage storageattach JavaTesting --storagectl "SATA Controller" --port 1 --type hdd --medium \\w7-2ua22514sf\VMTesting\JavaTestingDisk2.vmdk --mtype immutable --setuuid ""
vboxmanage startvm JavaTesting
goto END
:VBOXERROR
cls
echo Virtual Box is not installed. You cannot continue.
goto END
:END
REM pauseI hope I've explained this well enough.
Any help is greatly appreciated!