Start a VMware workstation when Linux boots

Start a VMware workstation when Linux boots:

Enter the command:

$ crontab -e

This will open the crontab in your favorite editor, vim on my machine. When open, add the following line:

@reboot sleep 20; /usr/bin/vmrun start "/path/to/vm.vmx" nogui

Safely shut down a VMware workstation when Linux shuts down or reboots:

Create a script in /etc/init.d named vmware-stop or something with the contents:

#!/bin/bash
/usr/bin/vmrun stop "/path/to/vm.vmx" nogui

And finally, create some symlinks for the appropriate run levels:

$ sudo chmod +x /etc/init.d/vmware-stop
$ sudo ln -s /etc/init.d/vmware-stop /etc/rc0.d/K00vmware-stop
$ sudo ln -s /etc/init.d/vmware-stop /etc/rc6.d/K06vmware-stop

Further reading:

Tags: , ,

Sunday, February 26th, 2012 Tips and Tricks

4 Comments to Start a VMware workstation when Linux boots

  • Joe says:

    Why have 2 symlinks to the same script in /etc/rc0.d/?

    Also, any hints on doing this for encrypted VMs without storing the passwords in plain text?

    Thanks.

    • David Rager says:

      Thanks for the heads up. That was a typo. One is supposed to go in /etc/rc0.d/ and the other in /etc/rc6.d/ I updated the post.

      For encrypted VMs I have not looked into it so I’m not sure what your options may be.

  • Peter says:

    It’s been a while since this was posted, but great blog! Very simple and helpful thanks.

    I am having a problem though with shutdown, the cron job works fine and VM starts as expected, however the systems fails to shutdown the VM on reboot or shutdown.

    I have run the ‘vmware-stop’ script from the command line and it works perfectly both using the actual script in init.d and the sym-links in run levels, when the script is run I can see the VM initiate shutdown almost immediately.

    However when the entire system is signaled to shutdown/reboot, the VM hangs on until it eventually get’s killed off by the system, NOT by the vmrun script.

    I changed both run levels to be ‘K00..’, my understanding is that this means it should be the first thing to happen on both shutdown and reboot, yet the script fails to shutdown the VM.

    Am I missing something obvious?

    (Host OS is CentOS 6.4, virtualisation is VMware Workstation 9, VMware Tools is up to date and as mentioned works perfectly if the vmware-stop is run from command line)

    Thanks in advance.

    • David says:

      Hi Peter,
      I’ve actually rebuilt my file server since I posted this and am no longer running VMware Workstation on it. I didn’t run into an issue like this while I had it set up so I’m not sure where to begin to troubleshoot it for you. The differences I am aware of are I was running an older VMware Workstation, version 5 or 6 I think and Ubuntu 10.4.

      If anyone has a solution I’d be interested in finding out and updating this post with that tip.

      Feel free to drop a line.
      Thanks,
      Dave.

  • Leave a Reply

     

    Comments are moderated due to spammers. Your comments will not appear until I review and approve them. If you left a question I will answer as best I can so be sure to check back.