Changes

Jump to: navigation, search
New page: VMware include a little known command-line tool with VMware Server and VMware Workstation called ''vmrun''. This tool allows a wide range of tasks to be performed on VMware based virtual m...
VMware include a little known command-line tool with VMware Server and VMware Workstation called ''vmrun''. This tool allows a wide range of tasks to be performed on VMware based virtual machines without having to use any of the graphical management interfaces such as VI Web Access.

The purpose of this HowTo is to explain how to control VMware Server 2.0 virtual machine power states from the command line using ''vmrun''.

== Finding the vmrun Tool ==

The ''vmrun'' tool is installed on the host system as part of the VMware Server and VMware Workstation virtualization products. Assuming a standard installation where the software is placed in the default location, the ''vmrun'' executable is located in ''\Program Files\VMware\VMware Server'' on Windows hosts and in the ''/usr/bin'' directory on Linux hosts.

== Understanding vmrun Command Line Syntax ==

The basic command line syntax for using ''vmrun'' varies slightly between VMware products, but can generally be summarized as follows:

vmrun ''<host authentication flags> <guest authentication flags> <command> <parameters>''

The ''host authentication flags'' are required to provide host, login and password information for the host system. These are essentially the same credentials that would be used when accessing the VI Web Access management interface. These flags are required only on VMware Server hosts, and are not needed for VMware Workstation:

<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>'''-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://myhostname:8333/sdk</nowiki>.
</td>
</tr>

<tr bgcolor="#e9e9e6">
<td>'''-P'''</td>
<td>The port number used by the host for virtual machine management. By default this will be 8333. If the port is specified in the URL (see above) this flag is not required.</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 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 used when logging in using the VI Web Access interface.</td>
</tr>

<tr>
<td>
<p>'''-p'''</p>
</td>
<td>
The password corresponding to the user name specified with ''-u'' as outlined above.
</td>
</tr>
</table>

The ''guest password flags'' are specified if the ''vmrun'' tool 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>
A suitable user name via which vmrun may log into the specified guest operating system
</td>
</tr>

<tr bgcolor="#e9e9e6">
<td>'''-gp'''</td>
<td>The corresponding password for the guest user specified using the ''-gu'' flag.</td>
</tr>
</table>

The ''command'' argument identifies to ''vmrun'' the task to be performed on the specified virtual machine. For example, ''start'', ''stop'' and ''reset'' are all valid commands. Other commands are available to perform tasks within a guest operating system, such as ''runProgramInGuest'' and ''deleteFileInGuest''.

The ''parameters'' arguments specify optional information required for a specific command. If, for example, the ''stop'' command is specified, the parameters argument is used to reference the .vmx file of the virtual machine which is to be powered off. 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.

When specifying the virtual machine on which a command is to be executed, the location of the virtual machine ''.vmx'' configuration file must be provided. For VMware Workstation, this involves specifying the full path of the file. For example:

<tt>"C:\VMware\VMachines\win2008.vmx"</tt>

In the case of VMware Server 2.0, which introduced the concept of ''datastores'', the name of the datastore in which the virtual machines resides must be provided together with the path of the corresponding ''.vmx'' file within that datastore. For example, to reference a virtual machine stored in the ''win2008'' sub-directory of the ''Vol1'' datastore, the vmrun path parameter would be defined as follows (note that the datastore name is enclosed in square brackets and separated from the sub-directory by a space character):

<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 ''vmhost'' running VMware Server 2 might appear as follows:

<pre>
vmrun -T server -h https://vmhost:8333/sdk -u root -p mypassword stop
"[Vol1] win2008/win2008.vmx"
</pre>

== Controlling Virtual Machine Power States ==

The power states of virtual machines can be controlled either locally or remotely using the ''vmrun'' tool. The commands associated with these tasks are as follows:

* '''start''' - Powers on the specified virtual machine. The virtual machine may started either with a GUI console visible, or no console using the ''gui'' and ''nogui'' options.

* '''stop''' - Powers off the specified virtual machine. The power off process can be specified as ''hard'' or ''soft''.

* '''reset''' - Reboots the specified virtual machine. The reboot process can be specified as ''hard'' or ''soft''.

* '''Suspend''' - Suspends a virtual machine allowing fast restart via the '''start''' command. The suspend process can be specified as ''hard'' or ''soft''.

* '''pause''' - Pauses the specified virtual machine.

* '''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 ''vmhost'' using the soft method:

<pre>
vmrun -T server -h https://vmhost:8333/sdk -u root -p mypassword stop
"[Vol1] win2008/win2008.vmx" soft
</pre>

Similarly, to subsequently start the same virtual machine:

<pre>
vmrun -T server -h https://vmhost:8333/sdk -u root -p mypassword reset
"[Vol1] win2008/win2008.vmx"
</pre>
1,798
edits

Navigation menu