blog

Photo of processor by Michael Dziedzic on Unsplash

Running VMWare Fusion 6 Headless

by

VMWare Fusion is great for running all kinds of virtual machines on my Mac and the new version 6 is a great upgrade. I’ll use it to run older versions of Mac OS X for testing, the Internet Explorer VMs from Microsoft for browser compatibility with web apps, and for running server apps on a virtual Linux box. Often when running a Linux server I’ll connect to the VM using SSH and use native Mac apps and iTerm 2 rather than access the VM through the virtual display. It’s always bothered me having that extra window around, even when minimized, so went in search of a way to run a VM without it, in a "headless" mode.

The answer is a tool called vmrun, and it’s included (but hidden) with VMWare Fusion. In the VMWare Fusion application bundle you’ll find a Contents/Library folder with a number of scripts and tools, one of them being vmrun. On my Mac I created a symlink to the vmrun binary in /usr/local/bin so it’s available in my PATH.

/usr/local/bin/vmrun -> /Applications/VMware Fusion.app/Contents/Library/vmrun

With that taken care of I can start up a headless VM instance with something like:

vmrun -T fusion start "/path/to/Ubuntu-12.04.vmwarevm/Ubuntu-12.04.vmx" nogui

Check out some of the other arguments and options such as list, clone, installTools and the Guest OS set of commands — there are some really useful tools to let you manage and interact with your VM from your OS X command line.

If you call vmrun without any options you’ll get the complete usage, listed here:

vmrun version 1.13.0 build-1331545
Usage: vmrun [AUTHENTICATION-FLAGS] COMMAND [PARAMETERS]
AUTHENTICATION-FLAGS
--------------------
These must appear before the command and any command parameters.
   -h <hostName>  (not needed for Fusion)
   -P <hostPort>  (not needed for Fusion)
   -T <hostType> (ws|fusion)
   -u <userName in host OS>  (not needed for Fusion)
   -p <password in host OS>  (not needed for Fusion)
   -vp <password for encrypted virtual machine>
   -gu <userName in guest OS>
   -gp <password in guest OS>
POWER COMMANDS           PARAMETERS           DESCRIPTION
--------------           ----------           -----------
start                    Path to vmx file     Start a VM or Team
                         [gui|nogui]
stop                     Path to vmx file     Stop a VM or Team
                         [hard|soft]
reset                    Path to vmx file     Reset a VM or Team
                         [hard|soft]
suspend                  Path to vmx file     Suspend a VM or Team
                         [hard|soft]
pause                    Path to vmx file     Pause a VM
unpause                  Path to vmx file     Unpause a VM
SNAPSHOT COMMANDS        PARAMETERS           DESCRIPTION
-----------------        ----------           -----------
listSnapshots            Path to vmx file     List all snapshots in a VM
                         [showTree]
snapshot                 Path to vmx file     Create a snapshot of a VM
                         Snapshot name
deleteSnapshot           Path to vmx file     Remove a snapshot from a VM
                         Snapshot name
                         [andDeleteChildren]
revertToSnapshot         Path to vmx file     Set VM state to a snapshot
                         Snapshot name
GUEST OS COMMANDS        PARAMETERS           DESCRIPTION
-----------------        ----------           -----------
runProgramInGuest        Path to vmx file     Run a program in Guest OS
                         [-noWait]
                         [-activeWindow]
                         [-interactive]
                         Complete-Path-To-Program
                         [Program arguments]
fileExistsInGuest        Path to vmx file     Check if a file exists in Guest OS
                         Path to file in guest
directoryExistsInGuest   Path to vmx file     Check if a directory exists in Guest OS
                         Path to directory in guest
setSharedFolderState     Path to vmx file     Modify a Host-Guest shared folder
                         Share name
                         Host path
                         writable | readonly
addSharedFolder          Path to vmx file     Add a Host-Guest shared folder
                         Share name
                         New host path
removeSharedFolder       Path to vmx file     Remove a Host-Guest shared folder
                         Share name
enableSharedFolders      Path to vmx file     Enable shared folders in Guest
                         [runtime]
disableSharedFolders     Path to vmx file     Disable shared folders in Guest
                         [runtime]
listProcessesInGuest     Path to vmx file     List running processes in Guest OS
killProcessInGuest       Path to vmx file     Kill a process in Guest OS
                         process id
runScriptInGuest         Path to vmx file     Run a script in Guest OS
                         [-noWait]
                         [-activeWindow]
                         [-interactive]
                         Interpreter path
                         Script text
deleteFileInGuest        Path to vmx file     Delete a file in Guest OS
Path in guest
createDirectoryInGuest   Path to vmx file     Create a directory in Guest OS
Directory path in guest
deleteDirectoryInGuest   Path to vmx file     Delete a directory in Guest OS
Directory path in guest
CreateTempfileInGuest    Path to vmx file     Create a temporary file in Guest OS
listDirectoryInGuest     Path to vmx file     List a directory in Guest OS
                         Directory path in guest
CopyFileFromHostToGuest  Path to vmx file     Copy a file from host OS to guest OS
Path on host             Path in guest
CopyFileFromGuestToHost  Path to vmx file     Copy a file from guest OS to host OS
Path in guest            Path on host
renameFileInGuest        Path to vmx file     Rename a file in Guest OS
                         Original name
                         New name
captureScreen            Path to vmx file     Capture the screen of the VM to a local file
Path on host
writeVariable            Path to vmx file     Write a variable in the VM state
                         [runtimeConfig|guestEnv|guestVar]
                         variable name
                         variable value
readVariable             Path to vmx file     Read a variable in the VM state
                         [runtimeConfig|guestEnv|guestVar]
                         variable name
getGuestIPAddress        Path to vmx file     Gets the IP address of the guest
                         [-wait]
VPROBE COMMANDS          PARAMETERS           DESCRIPTION
---------------          ----------           -----------
vprobeVersion            Path to vmx file     List VP version
vprobeLoad               Path to vmx file     Load VP script
                         'VP script text'
vprobeLoadFile           Path to vmx file     Load VP file
                         Path to VP file
vprobeReset              Path to vmx file     Disable all vprobes
vprobeListProbes         Path to vmx file     List probes
vprobeListGlobals        Path to vmx file     List global variables
GENERAL COMMANDS         PARAMETERS           DESCRIPTION
----------------         ----------           -----------
list                                          List all running VMs
upgradevm                Path to vmx file     Upgrade VM file format, virtual hw
installTools             Path to vmx file     Install Tools in Guest
checkToolsState          Path to vmx file     Check the current Tools state
deleteVM                 Path to vmx file     Delete a VM
clone                    Path to vmx file     Create a copy of the VM
                         Path to destination vmx file
                         full|linked
                         [-snapshot=Snapshot Name]
                         [-cloneName=Name]
Examples:
Starting a virtual machine with Workstation on a Windows host
   vmrun -T ws start "c:\my VMs\myVM.vmx"
Stopping a virtual machine on an ESX host
   vmrun -T esx -h https://myHost.com/sdk -u hostUser -p hostPassword stop "[storage1] vm/myVM.vmx"
Running a program in a virtual machine with Workstation on a Windows host with Windows guest
   vmrun -T ws -gu guestUser -gp guestPassword runProgramInGuest "c:\my VMs\myVM.vmx" "c:\Program Files\myProgram.exe"
Running a program in a virtual machine with Server on a Linux host with Linux guest
   vmrun -T server -h https://myHost.com:8333/sdk -u hostUser -p hostPassword -gu guestUser -gp guestPassword runProgramInGuest "[standard] vm/myVM.vmx" /usr/bin/X11/xclock -display :0
Creating a snapshot of a virtual machine with Workstation on a Windows host
   vmrun -T ws snapshot "c:\my VMs\myVM.vmx" mySnapshot
Reverting to a snapshot with Workstation on a Windows host
   vmrun -T ws revertToSnapshot "c:\my VMs\myVM.vmx" mySnapshot
Deleting a snapshot with Workstation on a Windows host
   vmrun -T ws deleteSnapshot "c:\my VMs\myVM.vmx" mySnapshot
Enabling Shared Folders with Workstation on a Windows host
   vmrun -T ws enableSharedFolders "c:\my VMs\myVM.vmx"

+ more

Accurate Timing

Accurate Timing

In many tasks we need to do something at given intervals of time. The most obvious ways may not give you the best results. Time? Meh. The most basic tasks that don't have what you might call CPU-scale time requirements can be handled with the usual language and...

read more