Changes

Jump to: navigation, search

Working with VMware Tools Scripts and Power States

4,986 bytes added, 15:07, 13 October 2008
Creating Custom VMware Tools Scripts
The ''Advanced'' settings allow the VMware Tools installation on the guest operating system to be automatically updated if a newer version is available, and to specify whether the guest operating system time should be synchronized with that of the host.
 
== The Default VMware Tools Scripts ==
 
If a virtual machine is configured to use VMware Tools scripts then either the default scripts installed with Vmware Tools, or custom scripts may be used. On Windows based guest operating systems, the default scripts take the form of Windows Batch files and are located in \Program Files\VMware\VMware Tools. On Linux guests the default scripts are shell scripts and reside in /etc/vmware-tools. On both guest types the files are descriptively named ''poweroff-vm-default'', ''poweron-vm-default'', ''resume-vm-default'' and ''suspend-vm-default''.
 
A review of the content of these scripts using a text or programmers editor will reveal that by default they actually do very little. For example, with the exception of suspend and resume, the Windows VMware Tools scripts contain nothing but a couple of comment lines. The real power of the Vmware Tools scripts is the ability to configure custom scripts.
== Creating Custom VMware Tools Scripts ==
 
As described in the previous section, the default scripts provided may be overridden using custom scripts. Custom scripts may be created either by modifying the default scripts, or by creating new scripts and configuring VMware Tools to use the new script in place of the default script. Custom scripts may be edited using any suitable text or programming editor, or by using the ''Edit...'' button located on the ''Scripts'' tab of the Vmware Tools control panel (for more details on the VMware control panel read [[The VMware Tools Control Panel]] chapter of this book). Note that the use of the control panel script editing feature on Linux will require knowledge of the ''vi'' editor. Those lacking the necessary skills with ''vi'' should consider directly creating and editing the custom scripts using their preferred editor outside the context of the control panel.
 
To create a custom script using the VMware Tools control panel, click on the ''Scripts'' tab and select the power change event for which the custom script is to be created from the menu. Ensure that the ''Use script'' option is selected and click on ''Custom Script'' at which point the text box containing the path to the script and the ''Browse'' and ''Edit'' buttons will be enabled. To edit the default script simply click on the ''Edit'' button and make the modification in the resulting edit window. To edit an existing custom script or create an entirely new script, enter the path and name of the script file into the the text field and press the ''Edit'' button. Once the script is complete, save the file and exit the editor to return to the control panel.
 
If custom scripts are being created outside of the VMware Tools control panel (and are new files rather than modifications to the existing default scripts) it will be necessary to configure VMware Tools to use these scripts. To achieve this, open the VMware Tools control panel, select the ''Scripts'' tab and choose the appropriate power state from the drop down menu. Ensure that ''Use scripts'' and ''Custom Script'' are both selected, use the ''Browse'' feature to navigate to and select the new custom script and click on ''OK'' to apply the change.
 
On Solaris, FreeBSD and Linux systems, it will be necessary to make new script files executable before they will run. To do this, use the ''chomd'' command. For example:
 
<pre>
chmod 755 /etc/vmware-tools/poweroff-vm-custom
</pre>
 
To test a custom script at any time, use the ''Run Now'' button on the control panel ''Scripts'' screen.
 
== Passing a String from the Host to the Guest ==
 
A string (in other words a sequence of characters) may be passed from the host system to the guest where it may be used within a VMware Tools script, or any other script for that matter. This is achieved by assigning the string to be passed to the guest to the ''machine.id'' value in the ''.vmx'' configuration file of the virtual machine in which the guest is running. For example, to pass the string "Virtuatopia Labs" through to the guest, the ''machine.id'' line in the .vmx file would read as follows:
 
<pre>
machine.id = "Virtuatopia Labs"
</pre>
 
The string may subsequently be obtained from within the guest operating system on Linux using the following command:
 
<pre>
vmware-guestd --cmd 'machine.id.get'
Virtuatopia Labs
</pre>
 
The equivalent command on a Windows guest is as follows:
 
<pre>
VMwareService --cmd machine.id.get'
Virtuatopia Labs
</pre>
 
This technique can be particularly useful in situations where the hostname or IP address to be used by the guest operating system needs to be provided by the host system at system start up time.
 
== Linux, Solaris and FreeBSD Reboot and Shutdown Commands ==
 
In addition to the scripts outlined above, an additional mechanism is provided on Linux, Solaris and FreeBSD guests for executing commands when a virtual machine is either shut down or rebooted. These are specified in the ''/etc'vmware-tools.conf'' file using the '''halt-command ='' and '''reboot-command = ''' directives.
1,798
edits

Navigation menu