Sunday, December 6, 2009

vmrun deconstructed

In my last post I introduced the vmrun command to allow vmware fusion 3 to run a virtual machine headless. Sit down and get comfortable because now I am going to give a brief tutorial on the vmrun command and why it might be the most valuable addition to vmware fusion.

Ok so why would you ever want to run a virtual machine from the command line? Well if you are asking the question you probably wouldn't want to but I will answer it anyway. Not every use of a virtual machine requires graphical input. Sure its great to run windows on mac and VMware fusion really is the way forward in that respect. But if you want to run a virtual LAMP server for example (Linux Apache MySQL and PHP) the graphical user interface (gui) of Fusion is mostly useless can often get in the way. Running in headless mode eliminates the gui and leaves you with a clean clutter free desktop in addition to saving that extra bit of RAM that the gui takes up which is no small reward when running multiple vm's simultaneously.

So the great guys at VMware have given us a really neat way into interacting with virtual machines from the command line and in the next few posts I am going to try and give you a brief introduction to the kind of things you can do with this cool tool.

Let's start by deconstructing the command I introduced in my last post on running headless.

/Library/Application\ Support/VMware\ Fusion/vmrun -T fusion start /Users/USERNAME/Documents/Virtual\ Machines.localized/VA-LAMP.vmwarevm/VA-LAMP.vmx nogui

1. Location

/Library/Application\ Support/VMware\ Fusion/vmrun -T fusion start /Users/USERNAME/Documents/Virtual\ Machines.localized/VA-LAMP.vmwarevm/VA-LAMP.vmx nogui

The vmrun tool is located in the VMware Fusion folder in Application Support in the Library folder at the root of your hard disk.

2. The vmrun command

/Library/Application\ Support/VMware\ Fusion/vmrun -T fusion start /Users/USERNAME/Documents/Virtual\ Machines.localized/VA-LAMP.vmwarevm/VA-LAMP.vmx nogui

This tells the vmrun application to start and hey by the way we are going to run vmware fusion.

3. Starting the virtual machine

/Library/Application\ Support/VMware\ Fusion/vmrun -T fusion start /Users/USERNAME/Documents/Virtual\ Machines.localized/VA-LAMP.vmwarevm/VA-LAMP.vmx nogui

The start command which we are passing to vmware fusion tells it that we want to start a virtual machine located at the following path.

4. Headless

/Library/Application\ Support/VMware\ Fusion/vmrun -T fusion start /Users/USERNAME/Documents/Virtual\ Machines.localized/VA-LAMP.vmwarevm/VA-LAMP.vmx nogui

Now we have told vmrun to start the virtual machine of choice with vmware fusion the last option we pass is nogui. Up to this point you could have done everything from within the VMware Fusion gui but this is the deal breaker. We are now saying can you do all of this but by the way I don't want to see any graphical output please.

I hope this has helped iron out any teething problems with vmrun, in the next post I will go through some of the other cool things that can be done with vmrun.


2 comments:

  1. Thanks chris, good post, one note: As noted here (http://communities.vmware.com/message/1648085), there is one extra step (without which I always had a failure message: Error: The file is already in use).

    You need to delete the VM from your machine library before it is vmrun-able.

    ReplyDelete
  2. @Matt - actually, there's another way. If you "quit" the vmware UI application (eg: let everything run in the background; Ctrl-Q, or File->Quit->Run-in-background), then you can use the vmrun command just fine (and when you re-start /usr/bin/vmware - the machine in your library is happily running)

    ReplyDelete