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!


Friday, October 2, 2009

Apple broke Acrobat 8 - How to make pdfs now

After upgrading to Snow Leopard I found that my PDF printer was broken. The good news is that if you upgrade to Acrobat 9 then you can again print to PDF however the bad news is its not free. After no luck from Adobe technical support I took the bold move to e-mail one of the Acrobat team and ask how to create pdf files in the same way it was before. Luck was in my
favour and he responded very quickly and was very helpful. The following is a quick tutorial on how to generate a pdf file in Acrobat 8 pro under OS X 10.6.

1. Select the document you want to turn into a pdf. In this case I chose the apple home page in safari. Go to the file menu and select print.
2. From the print dialogue box click on pdf in the bottom left of the window and select "save as PDF..."
3. Choose a name and location to save the pdf and click save
4. Open your newly created pdf file in Acrobat Pro and from the Advanced menu select "PDF Optimizer"
5. At this point you can either review and change the optimisation settings such as picture compression or font embedding or just accept the default settings and let Acrobat do its thing.
6. I have included a screen shot showing the file size change from the original file to the smaller optimised file produced by Acrobat






Wednesday, August 12, 2009

It is truly amazing how small we are.

Monday, August 10, 2009

Green Hosting



As you sit surfing the net have you ever thought about how much energy is being consumed to deliver web content to your home? Until recently I had not. It is so simple to surf the web expecting pages to load lightning fast but this comes with a cost. Vast data centers consuming large amounts of power are required to deliver rich web content in this plugged in age.

I was very pleased to find out that my webhost 1&1 is now 100% green hosting. Does this mean that they have windmills sitting on top of their data centers or some fancy geothermal energy production plant on site? Well the answer is no. Well in this case does it mean that there is some special renewable energy electricity grid? Again the answer is no, all the energy produced is delivered to the same energy grids.

How does it work?
Consumers buy renewable energy credits (RECs). For every 1000kW hour of energy produced by a renewable energy generator a single unique REC is issued. This provides an audit trail which ensures that although the energy a consumer receives may not technically have been generated in a renewable manner the energy they are funding is renewable energy.

For more information look at the following links









Sunday, August 2, 2009

QtiPlot

QtiPlot is a great full featured open source alternative to Origin. It is free for the linux platform but for OS X and windows 32 a fee of 20-50 euros is required for access to the binaries. In the spirit of open source I decided to compile it myself. After failing a few times I investigated compiling it via macports. Again the process failed with an error relating to python scripts. The following workaround details how to disable python scripting and successfully install qtiplot on osx using macports.

1. Install macports from the macports website.
2. Open Terminal and issue the following command
sudo port install qtiplot (all the dependencies should install however the qtiplot build will fail)

3. Remove the qtiplot download with the following command
sudo port clean qtiplot
4. Fetch the qtiplot archive
sudo port fetch qtiplot
5. Configure the qtiplot install
sudo port configure qtilot
This will extract the qtiplot files

6. Navigate to the qtiplot folder in /opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_release_ports_aqua_qtiplot/work/qtiplot-XXX/qtiplot

7. Open qtiplot.pro with TextEdit and comment out the # SCRIPTING_LANGS += Python line with a #

8. Return to the Terminal and issue
sudo port build qtiplot

9. Install qtiplot with
sudo port destroot qtiplot

10. Finally issue the following command to install qtiplot in /Applications/Macports

sudo port install qtiplot