[SOLVED] Reliable way to start VirtualBox as a guest on macOS High Sierra

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
paulbeard
Posts: 15
Joined: 13. Jun 2013, 18:51

[SOLVED] Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by paulbeard »

So The Official Way™ doesn't work.

Code: Select all

2.21.3. Mac OS X: Starting the Autostart Service With launchd
On Mac OS X, launchd is used to start the Oracle VM VirtualBox autostart service. An example configuration file can be found in /Applications/VirtualBox.app/Contents/MacOS/org.virtualbox.vboxautostart.plist. To enable the service copy the file to /Library/LaunchDaemons and change the Disabled key from true to false. Furthermore replace the second parameter to an existing configuration file which has the same format as on Linux, see Section 2.21.1, “Linux: Starting the Autostart Service With init”.

To manually start the service use the following command:

Copy# launchctl load /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist
For additional information on how launchd services can be configured see:

http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPSystemStartup/BPSystemStartup.html.
I have read countless incorrect ways to do this. This is just one more that doesn't, despite its official provenance.

The plist file is a wrapper around

Code: Select all

/Applications/VirtualBox.app/Contents/MacOS/VBoxAutostartDarwin.sh /etc/vbox/autostart.cfg 
and this gives me

Code: Select all

VBoxAutostart: error: User is not allowed to autostart VMs
VBoxAutostart: error: User is not allowed to autostart VMs
VBoxAutostart: error: User is not allowed to autostart VMs
00:00:00.000405 main     VirtualBox Autostart 6.1.28 r147628 darwin.amd64 (Oct 18 2021 19:59:14) release log
00:00:00.000408 main     Log opened 2021-11-17T01:47:51.817796000Z
00:00:00.000409 main     Build Type: release
00:00:00.000430 main     OS Product: Darwin
00:00:00.000441 main     OS Release: 17.7.0
00:00:00.000452 main     OS Version: Darwin Kernel Version 17.7.0: Fri Oct 30 13:34:27 PDT 2020; root:xnu-4570.71.82.8~1/RELEASE_X86_64
00:00:00.000609 main     DMI Product Name: iMac12,1
00:00:00.000680 main     DMI Product Version: 1.0
00:00:00.000684 main     Firmware type: failed - VERR_NOT_SUPPORTED
00:00:00.000720 main     Host RAM: 12288MB (12.0GB) total, 10469MB (10.2GB) available
00:00:00.000723 main     Executable: /Applications/VirtualBox.app/Contents/MacOS/VBoxAutostart
00:00:00.000723 main     Process ID: 3596
00:00:00.000724 main     Package type: DARWIN_64BITS_GENERIC
That permissions problem looks serious. But is it?

Code: Select all

bash-3.2# cat /etc/vbox/autostart.cfg
default_policy = deny
paul = {
    allow = true
    startup_delay = 10
}
Sure looks like it should work.

If I change that deny to allow…

Code: Select all

VBoxAutostart: error: could not get base directory: VERR_PATH_NOT_FOUND
No idea what base directory it's looking for or how to set it.

I just had to reinstall VirtualBox twice and now have the latest version with the extension pack installed.

The only reliable way to start it is still

Code: Select all

	/usr/local/bin/VBoxManage startvm ed8b8574-9a71-4b27-b0a9-c6ac81721fe2
which isn't useful if I can't get to the console of the host system.

Code: Select all

/usr/local/bin/VBoxHeadless
fails with missing kernel module errors, necessitating another reinstall of VirtualBox. Again, not something one can do without physical access to the host machine.

Tried rolling my own plist file and getting rid of all the other junk:

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>Label</key>
<string>org.virtualbox.autostart</string>
<key>ProgramArguments</key>
<array>
	<string>/usr/local/bin/VBoxManage</string>
	<string>startvm</string>
	<string>ed8b8574-9a71-4b27-b0a9-c6ac81721fe2</string>
</array>
<key>Disabled</key><false/>
<key>KeepAlive</key><true/>
</dict>
</plist>
No better but no worse. Has anyone ever gotten this to work?
Last edited by paulbeard on 31. Dec 2021, 03:35, edited 1 time in total.
granada29
Volunteer
Posts: 690
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by granada29 »

The problem you are seeing with the kernel modules not being loaded is a known bug in VirtualBox 6.1.28 and earlier when running macOS Monterey.

You will see this discussed in viewtopic.php?f=39&t=104272&start=15 where the interim solution is to install a test build of 6.1.29

VirtualBox versions earlier than 6.1.28 will case a kernel panic on macOS Monterey, so best to use at least 6.1.28
There is no need to re-install VirtualBox after a boot - You can manually load (or use a shell script) the required modules. This is also discussed in the linked topic.
paulbeard
Posts: 15
Joined: 13. Jun 2013, 18:51

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by paulbeard »

The problem I am seeing isn't about kexts not loading. I am not running Monterey on this system. It used to start reliably from the command line in earlier versions so perhaps dropping back to an earlier release will fix that problem. But my main issue is autostarting at boot time. Other services can do, both system-provided and third-party services. I'd like to keep the focus there. If I need to drop back to an earlier 6.1.x release, I'd be interested in knowing which one.
granada29
Volunteer
Posts: 690
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by granada29 »

Just to be clear. Are you trying to run your VM at system boot (i.e. no users logged in) or are you trying to have it start after login?

If the answer is system boot, then the GUI is not available and you need to be doing a headless start.

If it's after the user has logged in then startvm is fine, but you should probably be starting from a login script, rather than the system boot script.
paulbeard
Posts: 15
Joined: 13. Jun 2013, 18:51

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by paulbeard »

I need it to start at system boot. If the host reboots for any reason, I want virtualbox to start the VM as it reboots. Running the command from cron via @reboot has never worked so launchd seems to be only thing. If only I could get it to work…seems simple enough from looking at other working plist examples but something ain't right..
granada29
Volunteer
Posts: 690
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by granada29 »

Then you definitely need to do a headless start.
See user manual 7.1.2 for 2 ways of doing this.

1. VBoxManage startvm <VM-name> --type headless
2. VBoxHeadless --startvm <uuid>|<vmname>

Your script also needs to start the VM with the correct user - its a really bad idea to have VirtualBox running as the root user. Also a good idea to use full path names - you can't assume that the ususal default PATH has been set.
paulbeard
Posts: 15
Joined: 13. Jun 2013, 18:51

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by paulbeard »

I couldn't get VBoxHeadless to run but perhaps that's resolved now. This shouldn't be this hard to do, and it would be favorite if the Official™ docs could be relied on. Traveling soon which makes this a task I need to address.

The username should be picked up when the script loads, based on the directory/path is loads from. I guess I'll find out if that assumption pans out.
paulbeard
Posts: 15
Joined: 13. Jun 2013, 18:51

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by paulbeard »

Just had occasion to test this and it still doesn't work. The plist file I set up was gone when the host system restarted. Not great. Commandline uses of VBoxManage and VBoxHeadless failed. In the UI admin tool, there were kext errors so I installed the latest version. This is not Monterey or Big Sur…it's High Sierra as it says at the top. Maybe I need to drop way back to a 5.x version of Vbox.

Still in the hunt for a reliable way to start VirtualBox as a guest on macOS High Sierra with no intervention or user action. Don't even care if it runs as root.
granada29
Volunteer
Posts: 690
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by granada29 »

I wrote a program a couple of years ago that helps with configuring start at boot. It is signed and notarised.

https://whatroute.net/software/vboxstar ... -1.0.0.zip

I have never released it and there is no documentation, but you should be able to figure it out when you run it. It will install a launch daemon plist, a shell script and also the /etc/vbox file. If there is any interest, then I'll put together a brief HOWTO.

I just tried it out with a Windows 10 VM on macOS Sierra with VirtualBox-6.1.30 and it worked fine.

Before configuring the boot software I verified that the VM would load and run OK from the VirtualBox Manager.

My VM is configured on an external USB drive, so I configured it with a 30 sec start delay.

If you don't like it after trying it, there is an uninstall button that will remove the configuration.
paulbeard
Posts: 15
Joined: 13. Jun 2013, 18:51

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by paulbeard »

I'll take a look, thanks.

Took a minute of head scratching…it doesn't like a VM to be running which makes sense, I guess. But it started it just fine after I installed the autostartup bits. Nice work picking up the existing VMs…

Seems like a lot of work to make an app to do this, especially as Oracle doesn't seem bothered to do it.

Thanks for taking the time,
granada29
Volunteer
Posts: 690
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by granada29 »

paulbeard wrote: Seems like a lot of work to make an app to do this, especially as Oracle doesn't seem bothered to do it.
It is all in the VirtualBox documentation but many people have a fear of using the Terminal and not many have tried to get it working on macOS. Oracle have far more pressing issues than this rarely used feature so I understand why it's not in their gui.

I think the delay to allow USB disks to become visible was the key to finally getting it to work, but I also took care to make sure the VM would start as the specified user and not as root.

Anyway - I'm glad you got your boot startup working. Feel free to suggest improvements. I know documentation is always a good idea, and is also rarely consulted. The UI should be self explanatory.
paulbeard
Posts: 15
Joined: 13. Jun 2013, 18:51

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by paulbeard »

I live in the Terminal but launchctl just isn't clear. I haven't tested this with a reboot of the host yet…/fingers crossed

A lot of attempts to make this work, seems I'm not the only one chasing it. New OS releases and changes to launchctl don't help, I suspect.
paulbeard
Posts: 15
Joined: 13. Jun 2013, 18:51

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by paulbeard »

Well, I just had occasion to test this (power flickered enough to knock the host over) and it works like a charm. I wish the tool you made was standard issue for the virtual box installer…I see so many web pages on this, none of which work as well as yours. Thanks for making it and sharing it.
granada29
Volunteer
Posts: 690
Joined: 3. Mar 2015, 07:27
Primary OS: Mac OS X other
VBox Version: OSE other
Guest OSses: Linux, macOS, Windows

Re: Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by granada29 »

I am pleased to hear that it worked for you. Please edit the title of the topic and mark it as solved. That will help anyone else searching for how to do this.
Last edited by granada29 on 31. Dec 2021, 04:34, edited 1 time in total.
paulbeard
Posts: 15
Joined: 13. Jun 2013, 18:51

Re: [SOLVED] Reliable way to start VirtualBox as a guest on macOS High Sierra

Post by paulbeard »

Done. And thanks again.
Post Reply