VMware Fusion 2 and other VMware products include a command line utility called "vmrun". On OS X, you'll find that at "/Library/Application Support/VMware Fusion". You can download a PDF that describes its use at Using vmrun to Control Virtual Machines.
If you want a great guide to learning Fusion, consider Joe Kissel's Take Control of VMware Fusion 3, a free PDF E-book that will teach you everything you need to know.
You can use vmrun to start and stop virtual machines from the command line. You can suspend and reset machines also. That's all very simple:
vmrun start Ubuntu/Ubuntu.vmx vmrun suspend Ubuntu/Ubuntu.vmx vmrun start Ubuntu/Ubuntu.vmx vmrun stop Ubuntu/Ubuntu.vmx
What may be more interesting is that you can inspect the process list. You do need to install VMware tools first:
$ vmrun -gu apl -gp mypasswd listProcessesInGuest Ubuntu.vmx (long delay) Error: The VMware Tools are not running in the virtual machine: /Volumes/WD250/Ubuntu.vmwarevm/Ubuntu.vmx
Although VMware provides VMware Tools, Fusion can't actually install them - it simply mounts a virtual CD image and you do a manual install. For Ubuntu, that involves unpacking and compiling source, some of which failed when I tried it. However, most of the important things did compile and were able to be linked into the kernel so soon I could do:
$ vmrun -gu apl -gp mypasswd listProcessesInGuest Ubuntu.vmx Process list: 69 pid=1, owner=root, cmd=/sbin/init pid=914, owner=root, cmd=/sbin/udevd --daemon pid=2231, owner=root, cmd=/sbin/getty 38400 tty4 pid=2232, owner=root, cmd=/sbin/getty 38400 tty5 pid=2238, owner=root, cmd=/sbin/getty 38400 tty2 pid=2239, owner=root, cmd=/sbin/getty 38400 tty3 pid=2244, owner=root, cmd=/sbin/getty 38400 tty6 ..
You can do the same thing with a Windows VM.
I did have one other problem with the tools: it reset my X display to 1366x768 . That was impossible to read, so I did a Ctrl-Alt-F1 to get a login screen, edited /etc/X11/xorg.conf and did a "killall Xorg" to fix that.
There's more: you can create directories in a running Vm:
vmrun -gu apl -gp mypasswd createDirectoryInGuest ~/Desktop/Ubu*/Ubuntu.vmx /tmp/newdir
You can even run programs. That's not particularly exciting for Linux as you could do that several easier ways, but it could be interesting for Windows VM's.
Not that when you run programs, the output doesn't appear at your Mac. In the case of Linux, the output doesn't appear anywhere unless you have told the command to put its output somewhere. A script could redirect to /dev/tty1, an X11 app could use Display :0 and so on.
On Windows, the commands run in the VM console if you use the credentials of the logged in user.
I had a lot of trouble with running programs and scripts. I could easily run a script that I had created, say "/tmp/myscript":
date > /dev/tty1 date > /tmp/foo echo $1 >> /tmp/foo
That would run with
vmrun -gu apl -gp mypasswd runprogramInGuest ~/Desktop/Ubu*/Ubuntu.vmx /tmp/myscript args
If you were logged in on tty1 (ctrl-alt-F1) you'd see the output and of course would also find it in /tmp/foo.
However, I had problems running Perl scripts such as they show in examples. There doesn't appear to be any logging so it's very hard to figure out what might be wrong.. but it hardly matters as you can always just bundle up whatever you need in another script.
Vmrun makes it possible to automate tasks in virtual machines. I don't have any particular need for that right now, but it's easy to imagine cases where I would.
Got something to add? Send me email.
(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
Increase ad revenue 50-250% with Ezoic
Inexpensive and informative Apple related e-books:
Photos for Mac: A Take Control Crash Course
Take Control of Apple TV
Take control of Apple TV, Second Edition
Take Control of Automating Your Mac
Take Control of the Mac Command Line with Terminal, Second Edition