閱讀508 返回首頁    go iPhone_iPad_Mac_apple


How to auto start VMs on OS X Yosemite (10.10)

Hello,

 

I am running VirtualBox 4.3.20 r96996 on OS X Yosemite (10.10) Mac mini. I need to know the steps I can follow to auto start my Virtual Machines on reboot and/or on starting VirtualBox. Please advise me in the right direction



To start it on reboot, you would have to create a launchd plist to start up the VM. This is the syntax for the command

/usr/bin/VBoxManage stratvm <name of vm>

There is a program on the App Store called Lingon 3 that can help, or search the web for Launchd plist examples and write your own.

 

I don't know how to tell VB to start a VM on launch.

 

A way around that for just about any program would be to create an Automator Application or Applescript Application that opens the VM. Use that application to launch VB instead of VB itself.



I have the following configuration setup

 

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

  <key>Disabled</key>

  <false/>

  <key>KeepAlive</key>

  <true/>

  <key>Label</key>

  <string>org.virtualbox.vboxautostart</string>

  <key>ProgramArguments</key>

  <array>

    <string>/Applications/VirtualBox.app/Contents/MacOS/VBoxAutostartDarwin.sh</str ing>

    <string>/etc/vbox/autostart.cfg</string>

  </array>

  <key>RunAtLoad</key>

  <true/>

  <key>LaunchOnlyOnce</key>

  <false/>

</dict>

</plist>

 

 

$ cat /etc/vbox/autostart.cfg

default_policy = allow

 

 

Then I did the following

 

sudo chmod +x /Applications/VirtualBox.app/Contents/MacOS/VBoxAutostartDarwin.sh

sudo chown root:wheel /etc/vbox

sudo chown root:wheel /etc/vbox/autostart.cfg

sudo chown root:wheel /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist

 

and

 

VBoxManage modifyvm va1 --autostart-enabled on

VBoxManage modifyvm va1 --autostop-type acpishutdown

 

VBoxManage modifyvm va2 --autostart-enabled on

VBoxManage modifyvm va2 --autostop-type acpishutdown

 

Then, I issued the following command for verification:

sudo launchctl load /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist

 

However, only one VM starts at reboot and sometimes both don't start.

 

What am I missing here?



What happens if you add the program to your log in items?



@eric, I am not sure if I know how to do that correctly, can you please guide me?

 

Also, I realized that launchctl has upgraded in OS X Yosemite (10.10).  https://www.manpagez.com/man/1/launchctl/. The "load" and "unload" commands are called "legacy commands", and the new commands such as "kickstart", "bootstrap", "enable" are to be used.

 

No clue on how to use these new commands, please help!



VirtualBox is a GUI app. You can't set it to run at startup which you are doing because there is no GUI at startup.

As Eric pointed out the simple way of starting VB when you log in.

You could create a Launch Agent similar to what you did to have it launch at login for any user that logs in. Or, you can just put it in your user/Library/LaunchAgents

A Launch Agent runs at login.

A Launch Daemon runs at startup.

 

If you want to launch a specific VM (or VMs), I think you would need to create a LaunchAgent (not a Daemon) that would use the command I posted above as the thing to run. You don't need to create a shell file to run that line. You can just put it in the ProgramArguments.

<key>ProgramArguments</key>

  <array>

    <string>/usr/bin/VBoxManage</string>

    <string>startvm</string>

    <string><name of vm></string>

  </array>

 

You don't need to load, unload, kickstart, or whatever. If it is a valid plist and is in your LaunchAgents folder, it will load unless you specifically unload it and set the -w option which tells it to remember the last load/unload setting (which is now enable).

 

I don't know what you were doing with the whole autostart.cfg stuff.



Also note that you do not have to have VirtualBox running to launch a VM



The following is my /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist file as used on a Mac running Yosemite and I have multiple VMs starting automatically.

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "https://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Disabled</key>
  <false/>
  <key>KeepAlive</key>
  <true/>
  <key>Label</key>
  <string>org.virtualbox.vboxautostart</string>
  <key>ProgramArguments</key>
  <array>
  <string>/Applications/VirtualBox.app/Contents/MacOS/VBoxAutostartDarwin.sh</string>
  <string>/etc/vbox/autostart.cfg</string>
  </array>
</dict>
</plist>


I have the same setup (pasted config above), but does not work on Yosemite. Any idea what can be done for further troubleshooting?



Hi John,

 

What Yosemite version and VirtualBox version are you running?



jay_francisco wrote:

 

Hi John,

 

What Yosemite version and VirtualBox version are you running?

 

I have successfully got multiple VMs to auto-start with both Yosemite 10.10.3 and VirtualBox 4.3.12 r93733, and Mavericks 10.9.5 and VirtualBox 4.3.12 r93733. I know there are now newer versions of Virtualbox but I have not felt the need to upgrade it.



This leaves me confused on why its not working for my configuration. Any steps/procedures/checks you could suggest John?



Virtualbox has also terminal client and you can use Automator app on your Mac to create an application to launch your VM.

 

Please review this chapter. If you need some additional parameters for VBoxManage tool.

 

Open Automator app and as a type of document, choose Application.

 

Next, as an action choose Utilities > Run Shell Script (double click on it). Have a look at bellow screenshot:

Screen Shot 2015-06-30 at 23.01.59.png

In above example, my VM's name is Ubuntu 14.04 amd64 and full command is: VBoxManage startvm "Ubuntu 14.04 amd64"

As you probably know already, my VM is called Ubuntu 14.04 amd64.

 

Once your Automator document looks like above, save the document as the Application and save it in your user Application folder.

 

Then, go to System Preferences > Users & Groups > Login Items, and add your created application to the list of apps that will start automatically after your user has successfully logged in:

Screen Shot 2015-06-30 at 23.10.31.png

If you have more than one VM you might need to create an app for each individual VM.



Thanks iW00. This works perfectly.

 

Maybe I am asking too much for this, but is there a way to do the same at before logging in the system? So, on reboot, the VMs should start automatically at the lock screen, without the need to log in.

 

Is there any other way one can think of?

 

Thanks for all the help until now



Dear iW00,

 

i tested your script in Terminal directly and it worked, so i copy pasted the command to automator-shell-scripts, saved it to programs and there i get an error stating that "there was an error while trying to run the shell-script".

Do you have any idea, what could be wrong?

 

It somehow doesn't recognize the "VBoxManage: command not found" i think, but when i type it in terminal it works, only via Script or Automator tool it doesn't...

 

Best



最後更新:2017-10-04 22:58:28

  上一篇:go Cannot turn my Airdrop ON on Imac OSX Yosemite ...
  下一篇:go "This message has not been downloaded from the ...