Changes

Jump to: navigation, search
no edit summary
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>
<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>
<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>
<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:
== 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 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>
1,798
edits

Navigation menu