The command-line examples that follow work on VMware Fusion. Ubuntu16 is the virtual machine example for Linux and Win10 is the virtual machine example for Windows.

Reboot Commands

  • Reboot a virtual machine.

    vmrun reset Win10.vmwarevm/Win10.vmx soft

Snapshot Commands

  • Create a snapshot of a virtual machine

    vmrun snapshot Ubuntu16.vmwarevm/Ubuntu16.vmx mySnapshot

  • List snapshots on the virtual machine, showing the snapshot created in the previous command.

    vmrun listSnapshots Ubuntu16.vmwarevm/Ubuntu16.vmx

  • Revert to the snapshot you made, which suspends the virtual machine, and restart to resume operation.

    vmrun revertToSnapshot Ubuntu16.vmwarevm/Ubuntu16.vmx mySnapshot

    vmrun start Ubuntu16.vmwarevm/Ubuntu16.vmx

  • Delete the snapshot by specifying its name.

    vmrun deleteSnapshot Ubuntu16.vmwarevm/Ubuntu16.vmx mySnapshot

Network Adapter Commands

  • List all network adapters on a virtual machine.

    vmrun listNetworkAdapters Win10.vmwarevm/Win10.vmx

  • Add a NAT network adapter to a virtual machine.

    vmrun addNetworkAdapter Win10.vmwarevm/Win10.vmx nat

Host Network Commands

  • List all networks on the host.

    vmrun listHostNetworks

  • Add a port forwarding on a host network with examples provided of the host network name, protocol, host port, guest IP address, guest port, and description.

    sudo vmrun setPortForwarding vmnet2 tcp 8082 1.1.1.2 88 portforwarding-description

Running Guest Applications

Most vmrun guest operations require VMware Tools to be installed on the guest operating system.

  • Start the command tool, minimized, on a Windows guest.

    vmrun -gu guestUser -gp guestPassword runProgramInGuest Win10.vmwarevm/Win10.vmx -interactive cmd.exe

  • Start the command tool on a Windows guest as an active window on the desktop.

    vmrun -gu guestUser -gp guestPassword runProgramInGuest Win10.vmwarevm/Win10.vmx -activeWindow -interactive cmd.exe

  • Run a script on a Windows guest, with Perl as the script interpreter. Two separate examples follow.

    vmrun -gu guestUser -gp guestPassword runScriptInGuest Win10.vmwarevm/Win10.vmx -interactive "C:\perl\bin\perl.exe" "system('notepad.exe');"

    vmrun -gu guestUser -gp guestPassword runScriptInGuest Win10.vmwarevm/Win10.vmx -interactive "" "C:\perl\perl.exe C:\script.pl"

  • Run a batch script and keep running afterwards. To use cmd.exe on Windows, you must specify the script interpreter as null.

    vmrun -gu guestUser -gp guestPassword runScriptInGuest Win10.vmwarevm/Win10.vmx "" "cmd.exe /k \"C:\\Program Files\\Microsoft Visual Studio\\VC\\vcvarsall.bat\" x86"

  • Run a Bash shell script file or Perl script on a Linux guest.

    vmrun -gu guestUser -gp guestPassword runScriptInGuest Ubuntu16.vmwarevm/Ubuntu16.vmx -interactive "" "/bin/bash myscript"

    vmrun -gu guestUser -gp guestPassword runScriptInGuest Ubuntu16.vmwarevm/Ubuntu16.vmx -interactive "/usr/bin/perl" "system('firefox');"

  • Start an X clock on a Linux guest, which requires the -display option to appear on the console.

    vmrun -gu guestUser -gp guestPassword runProgramInGuest Ubuntu16.vmwarevm/Ubuntu16.vmx /usr/bin/xclock -display :0

  • Run the same X clock command, but return control back to the console immediately.

    vmrun -gu guestUser -gp guestPassword runProgramInGuest Ubuntu16.vmwarevm/Ubuntu16.vmx -noWait /usr/bin/xclock -display :0

  • Run Firefox.

    vmrun -gu guestUser -gp guestPassword runProgramInGuest Ubuntu16.vmwarevm/Ubuntu16.vmx /usr/bin/firefox --display=:0

  • Setting the guest environment with the guestEnv parameter requires root permission on Linux because the change affects subsequent commands issued by other users.

    vmrun -gu guestUser -gp guestPassword writeVariable Ubuntu16.vmwarevm/Ubuntu16.vmx guestEnv SRC tmp.example.com:1666

  • List processes in a Linux guest and end the process numbered 8192.

    vmrun -gu guestUser -gp guestPassword listProcessesInGuest Ubuntu16.vmwarevm/Ubuntu16.vmx

    vmrun -gu guestUser -gp guestPassword killProcessInGuest UUbuntu16.vmwarevm/Ubuntu16.vmx 8192

  • Run a Perl script on a Linux guest to remove DOS-style carriage returns from a file.

    vmrun -gu guestUser -gp guestPassword runProgramInGuest Ubuntu16.vmwarevm/Ubuntu16.vmx /usr/bin/perl -e "open(FILE, '>/tmp/unix.txt'); while (<>) { s/\r\n/\n/ ; print FILE}" /tmp/dos.txt

  • Run a Perl script on a Windows guest to insert DOS-style carriage returns in a file.

    vmrun -gu guestUser -gp guestPassword runProgramInGuest Win10.vmwarevm/Win10.vmx C:\cygwin\bin\perl.exe -e "open(FILE, ‘>C:\Users\user\dos.txt’); while (<>) { s/\n/\r\n/ ; print FILE}" C:\Users\guestUser\unix.txt

Guest to Host File Operations

  • To copy a file from the host to a guest, the user must have write permission on the destination.

    vmrun -gu guestUser -gp guestPassword copyFileFromHostToGuest Ubuntu16.vmwarevm/Ubuntu16.vmx ~/img.db /tmp/img.db

  • To copy a file from a guest to the host, the user must have read permission on the source file.

    vmrun -gu guestUser -gp guestPassword copyFileFromGuestToHost Ubuntu16.vmwarevm/Ubuntu16.vmx /home/username/addr addr.txt

  • To enable shared folders.

    vmrun enableSharedFolders Ubuntu16.vmwarevm/Ubuntu16.vmx

  • To share a folder on a Mac host with a particular Linux guest.
    Note: Before sharing folders, you must enable them with the enabledSharedFolders option, or by selecting Enable Shared Folders in the Sharing Settings panel of the virtual machine. On Linux guests, the /mnt/hgfs directory is available for sharing, but you can use a different directory for shared folders.

    vmrun addSharedFolder Ubuntu16.vmwarevm/Ubuntu16.vmx sharedFolderName ~/Share

  • To make a shared folder read‐only or to delete the shared folder.
    Note: Shared folders are writable by default.

    vmrun setSharedFolderState Ubuntu16.vmwarevm/Ubuntu16.vmx sharedFolderName ~/Share readonly

    vmrun removeSharedFolder Ubuntu16.vmwarevm/Ubuntu16.vmx sharedFolderName

    Note: On Windows Vista and Windows 7 or later guests, only the Administrator account can use copyFileFromHostToGuest and deleteFileInGuest options to write and delete files in the C:\ and system folders, or use the createDirectoryInGuest and deleteDirectoryInGuest options to modify system directories. Regular users, even those with administrator privilege, cannot perform these operations.

Guest Variables and Environment

  • From the host, set a guest variable on the virtual machines.

    vmrun writeVariable Win10.vmwarevm/Win10.vmx guestVar vmstartdate 21April2017

  • On the guest operating systems, read the guest variable that you just set.

    > rpctool.exe "info-get guestinfo.vmstartdate"

    $ vmware-rpctool "info-get guestinfo.vmstartdate"

  • From the host, set a guest environment variable on a Linux virtual machine and verify by writing the environment variables into a temporary file.
    vmrun writeVariable Ubuntu16.vmwarevm/Ubuntu16.vmx guestEnv LD_LIBRARY_PATH /usr/local/lib
    Guest user: root
    Guest password:
    vmrun runScriptInGuest Ubuntu16.vmwarevm/Ubuntu16.vmx /bin/bash "/usr/bin/env > /tmp/env.out"
    Guest user: root
    Guest password:
    Note: No output is sent to the host when you use the runScriptInGuest option with the vmrun command. Find the output of the command in the /tmp/env.out file on the guest.
  • On a Linux guest, determine the IP address and set it in a guest variable.
    $ ipaddr=`ifconfig eth0 | grep inet.addr`
    $ vmware-rpctool "info-set guestinfo.theip $ipaddr"
  • From the host, retrieve the IP address that was just set to the guest.

    vmrun readVariable Ubuntu10/Ubuntu10.vmx guestVar theip

General Commands

  • List running virtual machines.
    vmrun list
    Total running VMs: 2
    Absolute-path-to-virtual-machine.vmx
    
    Absolute-path-to-virtual-machine.vmx
  • Prepare to install VMware Tools.

    vmrun installTools Ubuntu16.vmwarevm/Ubuntu16.vmx

The Template Virtual Machine Commands

  • Download a VMware Project Photon operating system virtual machine.

    vmrun downloadPhotonVM ~