Sunday, December 6, 2009

vmrun cool tool!

In the last two posts I have introduced you to running VMware virtual machines headless and the basics of the vmrun command. In this post I want to outline some of the other great things you can do with vmrun. I will assume you know by now how to launch the vmrun command and run a virtual machine headless. So lets get to the good stuff.

1. Starting stopping pausing etc with vmrun

We already know the start command can be passed to vmrun but there are a whole bunch of other commands to do with vm powering on and off that we can exploit to control our virtual machine.


vmrun -T fusion start /path/to/vm/vmname.vmx nogui
This starts the virtual machine gui free.

vmrun -T fusion stop /path/to/vm/vmname.vmxhard
Stop the virtual machine without running any shutdown scripts (analogous to yanking the power cord from the wall).

vmrun -T fusion stop /path/to/vm/vmname.vmx soft
Stop the virtual machine and run the shutdown scripts (analogous to choosing shutdown from the apple/start menu depending on your preference).

vmrun -T fusion reset /path/to/vm/vmname.vmx hard
Restart the virtual machine without running any shutdown scripts (analogous to pressing the reset button on the front of your computer).

vmrun -T fusion reset /path/to/vm/vmname.vmx soft
Stop the virtual machine and run the shutdown scripts (analogous to choosing restart from the apple/start menu depending on your preference).

vmrun -T fusion pause /path/to/vm/vmname.vmx
Pause the virtual machine while running or in replay.

vmrun -T fusion unpause /path/to/vm/vmname.vmx
Unpause a paused virtual machine.

2. Snapshots
vmrun command can also control the taking and reverting of snapshots by passing the following commands.

vmrun -T fusion snapshot /path/to/vm/vmname.vmx snapshotname
Create a snapshot with the desired name.

vmrun -T fusion deleteSnapshot /path/to/vm/vmname.vmx snapshotname
Delete a snapshot with the desired name.

vmrun -T fusion revertToSnapshot /path/to/vm/vmname.vmx snapshotname
Revert to a snapshot with the desired name.

vmrun -T fusion listSnapshots /path/to/vm/vmname.vmx
List the snapshots associated with this virtual machine

3. Running commands on the virtual machine

This is possibly one of the most powerful tools that vmrun offers. The ability to run a commanf on the virtual machine without having any access like ssh or vnc. The only disadvantage is that you must know the exact location of the program you want to run. I will take the example of a linux guest running headless and creating a file using the touch command.

a) vmrun -T fusion -gu USERNAME -gp PASSWORD runProgramInGuest /Users/USERNAME/Documents/Virtual\ Machines.localized/VA-LAMP.vmwarevm/VA-LAMP.vmx /bin/touch /var/www/hello.txt

First we pass the username and password of an account on the guest virtual machine

b) vmrun -T fusion -gu USERNAME -gp PASSWORD runProgramInGuest /Users/USERNAME/Documents/Virtual\ Machines.localized/VA-LAMP.vmwarevm/VA-LAMP.vmx /bin/touch /var/www/hello.txt

Next we issue the runProgramInGuest command and tell vmrun which guest to run it in.

c) vmrun -T fusion -gu USERNAME -gp PASSWORD runProgramInGuest /Users/USERNAME/Documents/Virtual\ Machines.localized/VA-LAMP.vmwarevm/VA-LAMP.vmx /bin/touch /var/www/hello.txt

Finally we tell vmrun which application to run and what parameters to pass. In this case we touch the file hello.txt located in /var/www/

4. Listing and killing processes in the guest

vmrun -T fusion -gu USERNAME -gp PASSWORD listProcessesInGuest /Users/USERNAME/Documents/Virtual\ Machines.localized/VA-LAMP.vmwarevm/VA-LAMP.vmx
This command lists all the running processes in the guest but requires a valid username and password and for vmware tools to be installed.

vmrun -T fusion -gu USERNAME -gp PASSWORD killProcessInGuest/Users/USERNAME/Documents/Virtual\ Machines.localized/VA-LAMP.vmwarevm/VA-LAMP.vmx PID
Once you know a list of processes it is very easy to kill the desired rouge process

For more information and a complete list of all the cool things that can be done with vmrun checkout this pdf file from the vmware website. Happy VMing

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.


VMware Fusion 3 headless

VMware fusion has been out for a while now and I have just gotten round to trying to run a headless LAMP with client only networking for web development. Shock horror, the headless hack no longer works in Fusion 3, all is not lost. There is a little used tool introduced in Fusion 2 that most power users from the linux and windows community have been aware of for a long time. The command line vmrun is hidden away in /Library/Application Support/VMware Fusion/ directory. With a little digging one soon realizes the power of this tool to interact with virtual machines from the command line. It is now very easy to launch and run a virtual machine from the command line and interact with it in a variety of ways. I am going to give a brief tutorial on how to launch a headless virtual machine from the command line or a shell script. Remember to replace the USERNAME with your own username or the command will not work!! I have assumed that you have used headless mode before if not please refer to the full post on using the vmrun command.

1. You may or may not want to add the location of vmrun to your default path. I chose not to as I will mostly be interacting with vmrun through shell scripts.

2. To Launch the virtual machine named VA-LAMP.vmx which is located in the standard virtual machine directory enter the following command into the Terminal app.

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

To make this a command to launch the headless terminal from a file on the desktop just open text edit and enter the following text

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

Save the file as plain text to the desktop as headless.command

Now to make it executable fire up the terminal application and type

chmod +x $HOME/Desktop/headless.command

Congratulations! You can now run headless again!