Added possibility to start VMs during system boot

Discussions related to using VirtualBox on Mac OS X hosts.
Andrew Brehm
Posts: 42
Joined: 28. Mar 2012, 17:19

Re: Added possibility to start VMs during system boot

Post by Andrew Brehm »

ChipMcK wrote:
Andrew Brehm wrote:I also searched this forum.
This forum is for OS X Hosts. The feature was developed for Linux Hosts viewforum.php?f=7 .
There are a number of posts on that forum for the feature.
The feature was developed for all hosts.

And launchctl certainly only exists on Mac OS X.
mlcampbe
Posts: 4
Joined: 4. Nov 2010, 16:30
Primary OS: MS Windows Vista
VBox Version: PUEL
Guest OSses: 3.2.10

Re: Added possibility to start VMs during system boot

Post by mlcampbe »

Check the /Applications/VirtualBox.app/Contents/MacOS/VBoxAutostartDarwin.sh and see if the execute permissions are set on it or not. I found that it was not set on mine. Once I changed the file to 755 then I was able to manually run:

sudo /Applications/VirtualBox.app/Contents/MacOS/VBoxAutostartDarwin.sh --start /Users/mikecampbell/tools/vboxautostart.cfg

This started the image that was set with autostart. Have not tried it on a reboot but before I changed the permissions the above command did not run and returned a "command not found" error. After setting the correct permissions it now returns:

VirtualBox Autostart 4.2.4 r81684 darwin.amd64 (Oct 26 2012 19:04:51) release log
00:00:00.000237 main Log opened 2012-11-07T20:57:37.106319000Z
00:00:00.000248 main OS Product: Darwin
00:00:00.000252 main OS Release: 11.4.2
00:00:00.000256 main OS Version: Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64
00:00:00.001173 main DMI Product Name: iMac11,3
00:00:00.001815 main DMI Product Version: 1.0
00:00:00.001829 main Host RAM: 32768MB total, 14748MB available
00:00:00.001831 main Executable: /Applications/VirtualBox.app/Contents/MacOS/VBoxAutostart
00:00:00.001832 main Process ID: 84262
00:00:00.001832 main Package type: DARWIN_64BITS_GENERIC
kevinyank
Posts: 5
Joined: 5. Jul 2012, 03:28

Re: Added possibility to start VMs during system boot

Post by kevinyank »

Finally got this working on Mountain Lion with VirtualBox 4.2.4. The sample org.virtualbox.vboxautostart.plist file that is provided within the VirtualBox application bundle contains a couple of problematic keys:

Code: Select all

  <key>Disabled</key>
  <true/>
  <key>KeepAlive</key>
  <false/>
The VirtualBox documentation makes a point of instructing you to set the Disabled key to <false/>, but you also need to set KeepAlive to <true/> in order to get launchd to automatically start the service at boot (rather than waiting for some undeclared request to trigger the service launch).

My working org.virtualbox.vboxautostart.plist file is:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://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>--start</string>
    <string>/etc/vbox/autostart.cfg</string>
  </array>
</dict>
</plist>
My working /etc/vbox/autostart.cfg file is:

Code: Select all

default_policy = allow
(Although the documentation suggests setting the default_policy to deny and allowing individual users to autostart VMs, I couldn’t get this to work. When my autostart.cfg file was configured that way, the VBoxAutostartDarwin.sh script would output an error stating that the user was not allowed to autostart VMs.)
Andrew Brehm
Posts: 42
Joined: 28. Mar 2012, 17:19

Re: Added possibility to start VMs during system boot

Post by Andrew Brehm »

mlcampbe wrote:Check the /Applications/VirtualBox.app/Contents/MacOS/VBoxAutostartDarwin.sh and see if the execute permissions are set on it or not. I found that it was not set on mine. Once I changed the file to 755 then I was able to manually run:

sudo /Applications/VirtualBox.app/Contents/MacOS/VBoxAutostartDarwin.sh --start /Users/mikecampbell/tools/vboxautostart.cfg
Thank you. That was (part of) it.

Now I cannot set the autostartdbpath.

Code: Select all

$ sudo vx setproperty autostartdbpath /var/vbox
VBoxManage: error: Cannot set the autostart database path (VERR_NOT_SUPPORTED)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component SystemProperties, interface ISystemProperties, callee nsISupports
VBoxManage: error: Context: "COMSETTER(AutostartDatabasePath)(Bstr(a->argv[1]).raw())" at line 871 of file VBoxManageMisc.cpp
Any ideas?
Hète
Posts: 2
Joined: 23. Dec 2012, 04:13

Re: Added possibility to start VMs during system boot

Post by Hète »

Got exactly the same prob,

it will be very nice if we can get an exemple of config files 8)
Sova
Posts: 2
Joined: 25. Dec 2012, 01:52

Re: Added possibility to start VMs during system boot

Post by Sova »

Problem was fixed by myself.

first - change mode of file to run by launchd:
sudo chmod +x /Applications/VirtualBox.app/Contents/MacOS/VBoxAutostartDarwin.sh

second - I got error: 12/25/12 3:23:19.125 AM su[23603]: BAD SU mylogin to mylogin on tty
I fixed it by patching /Applications/VirtualBox.app/Contents/MacOS/VBoxAutostartDarwin.sh file.
I changed from: su ${user} -c "...."
to sudo -u ${user} ...

and last. I added key, and switched off KeepAlive to /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist :
<key>KeepAlive</key>
<false/>
<key>RunAtLoad</key>
<true/>

After that I have Machine running...
Sova
Posts: 2
Joined: 25. Dec 2012, 01:52

Re: Added possibility to start VMs during system boot

Post by Sova »

Andrew Brehm wrote: Thank you. That was (part of) it.

Now I cannot set the autostartdbpath.

Code: Select all

$ sudo vx setproperty autostartdbpath /var/vbox
VBoxManage: error: Cannot set the autostart database path (VERR_NOT_SUPPORTED)
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component SystemProperties, interface ISystemProperties, callee nsISupports
VBoxManage: error: Context: "COMSETTER(AutostartDatabasePath)(Bstr(a->argv[1]).raw())" at line 871 of file VBoxManageMisc.cpp
Any ideas?
Are you really sure that you need that?
You need only to run by user (not sudo): VBoxManage modifyvm YourVM --autostart-enabled on
To get YourVM name (not sudo): VBoxManage list vms

Run all this commands by user you have created VM.
Post Reply