Sunday, December 6, 2009

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!


10 comments:

  1. Will the VM continue running if you logout?

    ReplyDelete
  2. Sadly no, it would be nice but to do this requires something more. I will look into it when I have some time. Sorry

    ReplyDelete
  3. How would i use this to have a VM machine start once a mac machine has started. I have my Imac reboot every night and it logs in automatically. It would be great if the vm started automatically. In windows VMWare you can set the machines to start when host starts but I have yet to see this is VM Fusion..

    ReplyDelete
  4. Add your shell script to launchd. If I find time I will do a launchd tutorial

    ReplyDelete
  5. Curious how to stop it. I'd assume the same command, but swapping the word "Stop" for the word "Start"?

    ReplyDelete
  6. Hi Howard. You are correct you just substitute stop

    ReplyDelete
  7. Did you ever find time to look into the launchd idea?

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. First post didn't quite work as expected.

    Anyways, change this as needed.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
    "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <key>Label</key>
    <string>com.akarsoft.vm</string>
    <key>ProgramArguments</key>
    <array>
    <string>/Library/Application Support/VMware Fusion/vmrun</string>
    <string>-T</string>
    <string>fusion</string>
    <string>start</string>
    <string>/Users/akarsoft/Documents/Virtual Machines.localized/Linux.vmwarevm/Linux.vmx</string>
    <string>nogui</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    </dict>
    </plist>

    ReplyDelete
  10. Great work. The last time I'd briefly looked into this, I didn't find a workaround. This is terribly helpful!

    Also, here's some launchctl tips I found handy, for future readers:

    http://www.afp548.com/article.php?story=20050620071558293

    ReplyDelete