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

3 comments:

  1. Hi, excelent post!

    I'm having some problems trying to run TestComplete with vmrun.
    It's only recognize the first parameters of TestComplete program.
    Do you know how can I fix it?

    Thanks!!!

    ReplyDelete
  2. Does test complete command run correctly if you run it inside the vm without calling it with vmrun??

    ReplyDelete
  3. Yes.
    I call it from command line with the same parameters which I provided on vmrun, but it isn't work.

    ReplyDelete