Running VMware Player as a Windows ServiceFebruary 10, 2006 |
Generation 5 virtual machines can automatically scale the virtual machine's system RAM setting to fit available physical memory by adding a couple parameters to the .vmx file. memsize = "2048" In this case, the VM will have 2GB of RAM, if available. On machines with less than 2GB of RAM, Player will automatically adjust to fit available RAM. The memsize of 2048 is not the limit. If your environment has machines with more than 2GB of memory, then increase the number to suit. As far as I know, this is an undocumented feature. I found it in the .vmx file for the Browser Appliance Virtual Machine provided by VMware. |
1.2 Install VMware Player
On a the machine where the service will run (henceforth called the "target machine"), install VMware Player . This example uses version 1.0.1. Player can not co-exist with other VMware products on the same machine, so the target machine must be a different from the machine where the virtual machine was created. (This isn't strictly true, because you could uninstall the creating VMware product and install Player, but then you wouldn't be able to edit the machine and create new versions.)
It is possible to install VMware Player from the command line without all of the icons and Google Desktop integration. This makes automated deployment easy. Here's the command: VMware-player-1.0.1-19317.exe /s /v"/qn REBOOT=ReallySuppress ENABLE_GOOGLE_TOOLBAR=0 DISABLE_AUTORUN=0 STARTMENU_SHORTCUT=0 QUICKLAUNCH_SHORTCUT=0 DESKTOP_SHORTCUT=0 On first install, this installation command will have a return code 1303, indicating success with a reboot required to finish the install. Subsequent installs will have a return code of 0, indicating success. See Microsoft's documentation on Windows Installer Error Codes for details. The installation command was derived using Orca to find the checkbox names in the Player installer package. Check out Customonizing MSI installs from the command line for details. |
1.3 Make VMWare Player a service
- Obtain copies of instsrv.exe and srvany.exe from the appropriate Windows Resource Kit. For example, I used the Windows 2003 Resource Kit. Copy instsrv.exe and srvany.exe into %SYSTEMROOT% on the target machine.
- Copy the virtual machine files from the creating machine to a directory on the target machine. Not all files are needed; I only copied the files shown below.
- Add the fields to the .vmx file so that VMware Player suppresses all "Ok" message boxes and doesn't show a user interface.
server.vmx
... |
The hints.hideAll parameter was mentioned in the VMware - At Your Service! article in the June 2004 issue of Windows IT Pro. The msg.noOk parameter was found in DaveP's comment the VMware forums.
- Create the VirtualServer service on the target machine using instsrv.exe.
instsrv VirtualServer "%SYSTEMROOT%\System32\srvany.exe" |
Add the registry keys for srvany.exe so that it runs the vmplayer.exe with your virtual machine. For a detailed explaination of creating user-defined services in Windows, see the knowledge base article How to Create a User-Defined Service.
VirtualServer.reg
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\VirtualServer\Parameters] |
To use a different VMware product such as ACE, change the "Application" value for this key. To use a different virtual machine, change the "AppParameters" value.
- Create a startup batch file for the virtual machine called start-vm.bat. This script first checks to see if the virtual machine's files are installed and that the service isn't already running. It then kills any old VMware processes and removes various state files from the last run of the virtual machine. To finish, the VirtualServer service is started.
:: :: If the service is already running, then skip starting it :: To make sure that lingering processes are dead, force kill the process :: Remove *.lck, *.vmss from the grid directory :: Start the server service :noServer |
- Create a stop batch file for the virtual machine called stop-vm.bat. The stop script stops the VirtualServer service and kills any VMware processes related to running the virtual machine.
:: :: Start the service :: Force kill the processes :noServer |
Important: The virtual machine must be OK with a hard shutdown. Killing the virtual machine's processes is analagous to pulling the power cord on a physical computer. If virtual machine state doesn't matter, then you could use the nonpersistent disk feature. Since the disk image is not modified while running the virtual machine, a hard shutdown wouldn't have the chance of corrupting the virtual machine's disk.
To automate creating the VirtualServr service, add the following to your grid installation batch file. copy /Y instsrv.exe "%SYSTEMROOT%\system32\" instsrv VirtualServer "%SYSTEMROOT%\System32\srvany.exe" |
1.4 Running the virtual machine at startup
- Place the startup script in %SYSTEMROOT%\System32\GroupPolicy\Machine\Scripts\Startup. For this example, start-vm.bat is used as the startup script.
- On the target machine, make start-vm.bat run at system startup by adding it to the Startup group policy. gpedit.msc is the group policy editor. Run the command gpedit.msc to open the group policy editor. . Microsoft's document How Core Group Policy Works has an extensive explanation of how machine startup and shutdown policies are applied.
- Within the "Scripts (Startup/Shutdown)" section of the group policy editor, open the Startup Properties window. Click "Add" and type the name of the virtual machine startup script.
- Do steps 1-3 for for the Shutdown group policy, but use stop-vm.bat as the script. Adding the Shutdown group policy may not be strictly necessary, but it could be important to run stop-vm.bat if it contained more commands than just killing the virtual machine.
No comments:
Post a Comment