Autostarting VM on MacOS 12.2

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
SoCalDude
Posts: 6
Joined: 4. Nov 2021, 21:21

Autostarting VM on MacOS 12.2

Post by SoCalDude »

Hello,

I'm having some problems with auto-starting a VM on macOS Monterey 12.2 and am hoping someone from the forum can assist. I've read the user manual and even tried the VBoxStartAtBoot tool another member has shared here on the forum and in both cases, it's just not auto-starting on reboot.


Here are the files I believe are relevant. Maybe I just have something wrong but for the most part, these files were auto-generated. The VM name is "HA2" and the UUID is "98ff363b-4279-402e-bf24-a8e1ab472783" and I want it to run headless after a reboot (preferably before a user even logs in)


/Library/LaunchDaemons/org.virtualbox.vboxautostart.plist

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>Label</key>
	<string>org.virtualbox.vboxautostart</string>
	<key>ProgramArguments</key>
	<array>
		<string>/Library/Application Support/VBoxStartAtBoot/VBoxAutostartDarwin.sh</string>
		<string>/etc/vbox/autostart.cfg</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>LaunchOnlyOnce</key>
	<true/>
	<key>StandardErrorPath</key>
	<string>/tmp/vboxautostart.error.log</string>
	<key>StandardOutPath</key>
	<string>/tmp/vboxautostart.log</string>
</dict>
</plist>
/Library/LaunchDaemons/org.virtualbox.startup.plist

Code: Select all

<?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>org.virtualbox.startup</string>
    <key>Disabled</key>          <false/>
    <key>RunAtLoad</key>         <true/>
    <key>KeepAlive</key>         <false/>
    <key>LaunchOnlyOnce</key>    <true/>
    <key>ProgramArguments</key>
        <array>
            <string>/Library/Application Support/VirtualBox/LaunchDaemons/VirtualBoxStartup.sh</string>
            <string>restart</string>
        </array>
</dict>
</plist>
/Users/SoCalDude/Library/LaunchAgents/org.virtualbox.vboxwebsrv.plist

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>
  <true/>
  <key>KeepAlive</key>
  <false/>
  <key>Label</key>
  <string>org.virtualbox.vboxwebsvc</string>
  <key>Program</key>
  <string>/Applications/VirtualBox.app/Contents/MacOS/vboxwebsrv</string>
  <key>Sockets</key>
    <dict>
    <key>Listeners</key>
    <dict>
      <key>SockServiceName</key>
      <string>18083</string>
      <key>SockType</key>
      <string>stream</string>
      <key>SockFamily</key>
      <string>IPv4</string>
    </dict>
  </dict>
</dict>
</plist>
/etc/vbox/autostart.cfg

Code: Select all

## This file was created by VBoxStartAtBoot.
## Do not edit this file manually otherwise any changes you 
## make WILL be overriden next time you run VBoxStartAtBoot.


default_policy = allow
SoCalDude = {
	allow = true
}
Thanks in advance for any help you can provide.
SoCalDude
Posts: 6
Joined: 4. Nov 2021, 21:21

Re: Autostarting VM on MacOS 12.2

Post by SoCalDude »

When I run "launchctl load /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist" I get this error...

Code: Select all

Warning: Expecting a LaunchAgents path since the command was ran as user. Got LaunchDaemons instead.
`launchctl bootstrap` is a recommended alternative.
When I run "launchctl bootstrap load /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist" I get this error...

Code: Select all

Unrecognized target specifier, did you mean
system/com.apple.iomfb_fdr_loader
system/com.apple.logkextloadsd
system/com.apple.mDNSResponderHelper.reloaded
system/com.apple.mDNSResponder.reloaded
gui/501/com.apple.securityuploadd
gui/501/com.apple.storedownloadd
granada29
Volunteer
Posts: 702
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Autostarting VM on MacOS 12.2

Post by granada29 »

Try starting as root - this is what happens at boot

Code: Select all

sudo launchctl load /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist
SoCalDude
Posts: 6
Joined: 4. Nov 2021, 21:21

Re: Autostarting VM on MacOS 12.2

Post by SoCalDude »

granada29 wrote:Try starting as root - this is what happens at boot

Code: Select all

sudo launchctl load /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist
I tried running that in terminal, it prompted for my password and didn't give any error messages, however upon reboot the VM did not auto-start.

I do see these error logs...

/private/tmp/vboxautostart.log

Code: Select all

Looking for volume: /
Found volume: /
Starting VMs for: _mbsetupuser
Starting VMs for: SoCalDude
00:00:00.000298 main     VirtualBox Autostart 6.1.32 r149290 darwin.amd64 (Jan 13 2022 20:13:15) release log
00:00:00.000302 main     Log opened 2022-02-03T18:55:36.036501000Z
00:00:00.000303 main     Build Type: release
00:00:00.000313 main     OS Product: Darwin
00:00:00.000318 main     OS Release: 21.3.0
00:00:00.000323 main     OS Version: Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64
00:00:00.000433 main     DMI Product Name: MacPro6,1
00:00:00.000486 main     DMI Product Version: 1.0
00:00:00.000490 main     Firmware type: failed - VERR_NOT_SUPPORTED
00:00:00.000501 main     Host RAM: 32768MB (32.0GB) total, 29641MB (28.9GB) available
00:00:00.000504 main     Executable: /Applications/VirtualBox.app/Contents/MacOS/VBoxAutostart
00:00:00.000504 main     Process ID: 1389
00:00:00.000505 main     Package type: DARWIN_64BITS_GENERIC
Starting VMs for: root
00:00:00.000402 main     VirtualBox Autostart 6.1.32 r149290 darwin.amd64 (Jan 13 2022 20:13:15) release log
00:00:00.000407 main     Log opened 2022-02-03T18:55:36.120880000Z
00:00:00.000408 main     Build Type: release
00:00:00.000418 main     OS Product: Darwin
00:00:00.000423 main     OS Release: 21.3.0
00:00:00.000428 main     OS Version: Darwin Kernel Version 21.3.0: Wed Jan  5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_X86_64
00:00:00.000531 main     DMI Product Name: MacPro6,1
00:00:00.000587 main     DMI Product Version: 1.0
00:00:00.000591 main     Firmware type: failed - VERR_NOT_SUPPORTED
00:00:00.000603 main     Host RAM: 32768MB (32.0GB) total, 29641MB (28.9GB) available
00:00:00.000605 main     Executable: /Applications/VirtualBox.app/Contents/MacOS/VBoxAutostart
00:00:00.000606 main     Process ID: 1412
00:00:00.000606 main     Package type: DARWIN_64BITS_GENERIC
/private/tmp/vboxautostart.error.log

Code: Select all

Oracle VM VirtualBox Autostart 6.1.32
(C) 2022 Oracle Corporation
All rights reserved.

VBoxAutostart: error: could not get base directory: VERR_PATH_NOT_FOUND
Oracle VM VirtualBox Autostart 6.1.32
(C) 2022 Oracle Corporation
All rights reserved.

Oracle VM VirtualBox Autostart 6.1.32
(C) 2022 Oracle Corporation
All rights reserved.
However when macOS loads, I'm able to manually start the VM in normal or headless mode without any issues.
granada29
Volunteer
Posts: 702
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Autostarting VM on MacOS 12.2

Post by granada29 »

Is your VM located on an external USB volume?. External USB volumes are not mounted until the user has logged in and this perhaps explains why you are getting the error:

Code: Select all

VBoxAutostart: error: could not get base directory: VERR_PATH_NOT_FOUND
The scripts installed by VBoxStartAtBoot wait until the volume is visible before attempting to start the VM. I'm not sure that you are using those scripts any longer.
SoCalDude
Posts: 6
Joined: 4. Nov 2021, 21:21

Re: Autostarting VM on MacOS 12.2

Post by SoCalDude »

granada29 wrote:Is your VM located on an external USB volume?. External USB volumes are not mounted until the user has logged in and this perhaps explains why you are getting the error:

Code: Select all

VBoxAutostart: error: could not get base directory: VERR_PATH_NOT_FOUND
The scripts installed by VBoxStartAtBoot wait until the volume is visible before attempting to start the VM. I'm not sure that you are using those scripts any longer.
Thanks for the feedback. I’m running VirtualBox on the macOS main drive/partition. Not sure if that makes a difference or I should be trying to run it elsewhere.
granada29
Volunteer
Posts: 702
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Autostarting VM on MacOS 12.2

Post by granada29 »

There is no need to change your existing VM location. You say it's on the boot volume which to me implies that your VBoxAutostart configuration is running before the user file system is fully available.

Unfortunately macOS (launchctl etc) provides no mechanism for ordering start-at-boot tasks or even provide dependencies between launch tasks.

VBoxStartAtBoot lets you specify a delay (in seconds) to help overcome this as does the VirtualBox mechanism.
See: https://www.virtualbox.org/manual/UserM ... #autostart

I do have to say that VBoxStartAtBoot was written to overcome the difficulties you are experiencing, but of course it's your choice to use it or not.
SoCalDude
Posts: 6
Joined: 4. Nov 2021, 21:21

Re: Autostarting VM on MacOS 12.2

Post by SoCalDude »

granada29 wrote: I do have to say that VBoxStartAtBoot was written to overcome the difficulties you are experiencing, but of course it's your choice to use it or not.
This is the app I am referring to, a user has shared it on this forum and is how I am generating the files listed in the first post but for some reason Im not able to autostart the VM and was hoping that maybe someone would spot a simple configuration change needed to get it up and running.
granada29
Volunteer
Posts: 702
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Autostarting VM on MacOS 12.2

Post by granada29 »

Screenshot 2022-02-07 at 12.18.44 PM.png
Screenshot 2022-02-07 at 12.18.44 PM.png (124.55 KiB) Viewed 6578 times
OK. I am really not sure what is going on. I just tested with a debian VM and it all worked as expected. The screenshot shows how I configured the VM for starting at boot.
VortexRotor
Posts: 1
Joined: 10. Mar 2023, 23:06

Re: Autostarting VM on MacOS 12.2

Post by VortexRotor »

I have downloaded your tool but for the life of me I cannot get any VM's to show up to select. I have updated to the latest ver. I am running on MacMini w/ Moterey and VBox 7.0

Any idea what is going on here?
granada29
Volunteer
Posts: 702
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Autostarting VM on MacOS 12.2

Post by granada29 »

That is very odd.

What do see when you run the following command in Terminal? This is the command used by VBoxStartAtBoot to form the list.

Code: Select all

/Applications/VirtualBox.app/Contents/MacOS/VBoxManage list -s vms
Post Reply