Changes

Jump to: navigation, search
m
Text replacement - "<google>BUY_VMWARE_SERVER_2_BOTTOM</google>" to "<htmlet>vmware</htmlet>"
<table border="0" cellspacing="0" width="100%">
<tr>
<td width="20%">[[VMware Server 2.0 Security - Access, Roles and Permissions|Previous]]<td align="center">[[VMware Server 2.0 Essentials|Table of Contents]]<td width="20%" align="right"></td>
<tr>
<td width="20%">VMware Server 2.0 Security - Access, Roles and Permissions<td align="center"><td width="20%" align="right"></td>
</table>
<hr>
 
 
<htmlet>vmware</htmlet>
 
 
For all the ease of use provided by VMware Server's graphical tools, perhaps the most powerful tool supplied with various VMware products is a little known command line utility called ''vmrun''. Installed as standard with VMware Server, ''vmrun'' allows almost total control over virtual machines from the command line, either locally on the VMware Server host, or remotely over a network or internet connection. Capabilities of ''vmrun'' include starting, stopping, pausing, resuming and resetting virtual machines, executing commands within guest operating systems and taking snapshots. The primary goal of this chapter is to focus on these and other features of ''vmrun''.
The ''vmrun'' tool is installed by default with the VMware Server and VMware Workstation products. Assuming that a standard installation is performed, the ''vmrun'' executable is located in ''\Program Files\VMware\VMware Server'' on Windows hosts and ''/usr/bin'' on Linux.
The basic command line syntax for using ''vmrun'' varies between host platforms and VMware product, can but may be generally summarized as follows:
vmrun ''<host authentication flags> <guest authentication flags> <command> <parameters>''
<tr bgcolor="#cccccc" style="color:black" valign="top">
<th>
<p>Flag</p>
</th>
<th>
<p>Description</p>
</th>
</tr>
<tr>
<td>
<p>'''-h'''</p>
</td>
<td>
The https URL of the host to which ''vmrun'' is required to connect. Must also include the ''/sdk'' sub-directory and, optionally the port number (unless the ''-p'' flag below is used). For example, <nowiki>https://myhostnamehostname:8333/sdk</nowiki>.
</td>
</tr>
<tr>
<td>
<p>'''-T'''</p>
</td>
<td>
The type of VMware product which is running on the host. Options are ''ws'' for VMware Workstation, ''server'' to for VMware Server 2 and ''server1'' for VMware Server 1.
</td>
</tr>
<tr bgcolor="#e9e9e6">
<td>'''-u'''</td>
<td>The user name on the host to be used to log into the VMware management interface. The same as the user name that would be used when logging in using the VI Web Access interface.</td>
</tr>
<tr>
<td>
<p>'''-p'''</p>
</td>
<td>
</table>
The ''guest password authentication flags'' are specified if ''vmrun'' is required to log into the guest operating system to perform tasks such as work with guest files or execute commands. If such operations are not required, these flags may be omitted from the command line:
<table border="1" cellpadding="5" cellspacing="0" id="E3B" style="border-collapse: collapse; border-color:#cccccc; border-style: solid; border-width: 1px; margin-bottom:20px">
<tr bgcolor="#cccccc" style="color:black" valign="top">
<th>
<p>Flag</p>
</th>
<th>
<p>Description</p>
</th>
</tr>
<tr>
<td>
<p>'''-gu'''</p>
</td>
<td>
</table>
The ''command'' argument instructs ''vmrun'' on the task to be performed. For example, ''start'', ''stop'' and ''reset'' are all valid commands. As are the Other valid commands include those to perform tasks within a guest operating system, such as ''runProgramInGuest'' and ''deleteFileInGuest''.
The ''parameters'' arguments specify additional information required for a specific command. If, for example, the ''start'' command is specified, the parameters argument is used to reference the .vmx file of the virtual machine which is to be started. In the case of running guest commands, both the .vmx file of the target virtual machine and the path to the program to be executed must be provided as parameters.
<tt>"[Vol1] win2008/win2008.vmx"</tt>
Bringing all of these different command line arguments together, a typical ''vmrun'' command to start a virtual machine on a host named ''vmhosthostname'' running VMware Server 2 might appear as follows:
<pre>
vmrun -T server -h https://vmhosthostname:8333/sdk -u root -p mypassword stop
"[Vol1] win2008/win2008.vmx"
</pre>
<pre>
vmrun -T server -h https://myhosthostname:8333/sdk -u root -p mypassword list
Total running VMs: 2
[Vol1] win2008-1/win2008-1.vmx
<pre>
vmrun -T server -h https://myhosthostname:8333/sdk -u root -p mypassword installTools "[Vol1] CentOS 5.2/CentOS 5.2.vmx"
</pre>
<pre>
vmrun -T server -h https://xpshostname:8333/sdk -u root -p mypassword register "[Vol1] CentOS 5.2/CentOS 5.2.vmx"
</pre>
Similarly, to unregister a virtual machinefrom the host inventory:
<pre>
vmrun -T server -h https://xpshostname:8333/sdk -u root -p mypassword unregister "[Vol1] CentOS 5.2/CentOS 5.2.vmx"
</pre>
* '''unpause''' - Unpauses a paused virtual machine.
When the ''hard'' option is specified for the stop and suspend commands, the virtual machine state changes without giving the guest operating system the opportunity to execute shutdown or hibernate procedures (analogous to disconnecting the power to a physical computer system). To ensure an ordered power off or suspension, be sure to specify the ''soft'' option. For example, to power off a specific virtual machine residing on host named ''vmhosthostname'' using the soft method:
<pre>
vmrun -T server -h https://vmhosthostname:8333/sdk -u root -p mypassword stop
"[Vol1] win2008/win2008.vmx" soft
</pre>
<pre>
vmrun -T server -h https://vmhosthostname:8333/sdk -u root -p mypassword reset
"[Vol1] win2008/win2008.vmx"
</pre>
<pre>
vmrun -T server -h https://xpshostname:8333/sdk -u root -p mypassword snapshot
"[Vol1] CentOS 5.2/CentOS 5.2.vmx" MySnapshot
</pre>
<pre>
vmrun -T server -h https://xpshostname:8333/sdk -u root -p mypassword revertToSnapshot
"[Vol1] CentOS 5.2/CentOS 5.2.vmx" MySnapshot
</pre>
<pre>
vmrun -T server -h https://xpshostname:8333/sdk -u root -p mypassword start
"[Vol1] CentOS 5.2/CentOS 5.2.vmx"
</pre>
<pre>
vmrun -T server -h https://xpshostname:8333/sdk -u root -p mypassword deleteSnapshot
"[Vol1] CentOS 5.2/CentOS 5.2.vmx" MySnapshot
</pre>
<pre>
vmrun -T server -h https://xpshostname:8333/sdk -u root -p mypassword -gu administrator -gp guestpasswd
listProcessesInGuest "[Vol1] win2008-1/win2008-1.vmx"
<pre>
vmrun -T server -h https://xpshostname:8333/sdk -u root -p mypassword -gu administrator -gp guestpaswd
runProgramInGuest "[Vol1] win2008-1/win2008-1.vmx" -activeWindow "c:\windows\system32\cmd.exe"
</pre>
<pre>
vmrun -T server -h https://xpshostname:8333/sdk -u root -p mypassword -gu administrator -gp guestpasswd
runProgramInGuest "[Vol1] win2008-1/win2008-1.vmx"
-activeWindow -interactive "c:\windows\system32\notepad.exe"
<pre>
vmrun -T server -h https://xpshostname:8333/sdk -u root -p mypassword -gu administrator -gp guestpasswd
killProcessInGuest "[Vol1] win2008-1/win2008-1.vmx" 2368
</pre>
== Running Scripts Within a Guest ==
In addition to running executable programs on a guest operating system, ''vmrun'' also supports the running of scripts. Scripts are generally text based files containing instructions which a are executed by an interpreter. For example, a Perl script would be executed using the ''perl'' interpreter and Ruby script by the ''ruby'' interpreter. Whilst some operating systems and scripting languages allow scripts to be executed just as any other program is executed (and without referring to the interpreter in the command line) this is not always the case. In such situations the command line to execute the script must provide the path to the script as a command line argument to the interpreter. For example, suppose that the following Ruby script contained in a file called ''hello.rb'' located in ''/home/ruby'' needs to be executed:
<pre>
</pre>
In order to execute this script, the hello.rb file needs to be passed as a command line argument to the ''ruby'' interpreter program as follows:
<pre>
<pre>
vmrun -T server -h https://xpshostname:8333/sdk -u root -p mypassword -gu administrator -gp guestpasswd
runScriptInGuest "[Vol1] CentOS 5/Centos 5.vmx" /usr/bin/ruby /home/ruby/hello.rb
</pre>
== Using vmrun to Work with Guest Operating Systems Files and Directories ==
A particularly powerful feature of ''vmrun'' is the ability to interact with files residing in a guest operating systems from either the host, or a remote system. For example, vmrun can be used to identify the existence of a file in a specific virtual machine guest, delete a file, create a directory and copy files between guest and host. In each case, a user name and password valid for logging into the guest operating system must be provided using the ''-gu'' and ''-gp'' flags.
The following command commands require that VMware Tools be installed in the guest operating system. For more details on VMware Tools refer to the chapter entitled [[Understanding and Installing VMware Tools]].
To check for the existence of a particular file:
</pre>
Conversely, the to copy a file from the host to the guest:
<pre>
== Capturing a Virtual Machine Screenshot ==
A screenshot of the console of a running virtual machine may be captured and written to a file on the host using the vmrun ''captureScreen''command. The name of the file to which the image is to be written is supplied as a parameter to the command. Note that the image is created in PNG format, so the file should be given the appropriate ''.png'' filename extension. For example:
<pre>
vmrun -T server -h https://xpshostname:8333/sdk -u root -p mypassword -gu fred -gp guestpasswd captureScreen
"[Vol1] CentOS 5.2/CentOS 5.2.vmx" /home/fred/images/vm_screen.png
</pre>
 
 
<htmlet>vmware</htmlet>

Navigation menu