2011/07/17

Automatic start of Virtual Machine using VMware Player

I'm using VM with SVN server installed to store files and documents for customer and own projects. VMWare Server used so far to host this VM and start it automatically when my home PC started. But VMWare just retired its Server and suggested to use either ESX or Player. Using ESX is not an option for me and I have had good experience with Player so far (at least NAT does not crash so often as with Server). So I decided to use Windows Player on my new home PC. Unfortunately VMWare Player does not have capabilities to start VM during startup (but VMWare Workstation does not have such feature too). Let's fix this using build-in Windows 7 features. I'm using 64 bit host and 32 bit VM.

Setup automatic VM start

Windows Scheduler is good tool to start VM. Simply add new task to execute application during system start up. Put full path to vmplayer.exe as application name (C:\Program Files (x86)\VMware\VMware Player\vmplayer.exe) and path to VM configuration file as application parameter (e.g. C:\VMServers\SVN\SVN.vmx).  Disable all unnecessary execution options set by default then save created job. Unfortunately solution requires second part. Player starts VM right after reboot well but does not power off server during shutdown or reboot. So VM state could be inconsistent after reboot.

Add automatic VM shutdown

VMWare player does not allow to shutdown of existing VM using command line. But VMWare VIX does. Now shutdown event should be catched up. Windows scheduler does not allow to run any tasks on shutdown but LocalSystem policy can be used to run specific script during system shutdown. Start Run dialog (Win+R) then type gpedit.msc then Enter. In opened local group policy editor select System Configuration/Windows Settings/Scripts (Startup/Shudown). And add Shotdown.bat as shutdown script. Shudown.bat includes just single line:

"C:\Program Files (x86)\VMware\VMware VIX\vmrun.exe" -T player suspend C:\VMServers\SVN\SVN.vmx

It should be saved as C:\Windows\System32\GroupPolicy\Machine\Scripts\Shutdown\Shutdown.bat (note that GroupPolicy is hidden folder and administrative rights are needed to write to this folder).

Reasonable question is  why not to use local group policy startup script to start VM instead of scheduler. Unfortunately this does not work. Perhaps because not all necessary services started for VmWare Player

Hints


Replace suspend with shutdown if you need to make VM reboot for some reason.

VMWare Server allows to attach to console of auto-started VM. Unfortunately this is not the case for Player. Started instance is running on another desktop so cannot be viewed. In case of any problem VM can be suspended then started again using vmrun.exe. In this case restored VM should start on current desktop:

"C:\Program Files (x86)\VMware\VMware VIX\vmrun.exe" -T player suspend C:\VMServers\SVN\SVN.vmx
"C:\Program Files (x86)\VMware\VMware VIX\vmrun.exe" -T player start C:\VMServers\SVN\SVN.vmx 

No comments:

Post a Comment