Skip to content

Instantly share code, notes, and snippets.

@str8edgedave
Last active December 21, 2021 21:01
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save str8edgedave/b0b96e12396aaa7d383456778079ee7b to your computer and use it in GitHub Desktop.
Save str8edgedave/b0b96e12396aaa7d383456778079ee7b to your computer and use it in GitHub Desktop.
Auto-starting VirtualBox VMs on MacOS High Sierra

Auto-starting VirtualBox VMs on MacOS High Sierra

Updated May 21/2018

There are lots of different how-tos out there for automatically launching VMs using VirtualBox on MacOS. Most of them focus on older versions of VirtualBox or old versions of MacOS.

Tested using MacOS High Sierra 10.13.4 running VirtualBox 5.2.12. The guest OS is Fedora 28.

Following the instructions on the VirtualBox website (https://www.virtualbox.org/manual/ch09.html#autostart), copy the Virtualbox autostart plist template file to your system's LaunchDaemons folder.

david$ sudo cp \
    /Applications/VirtualBox.app/Contents/MacOS/org.virtualbox.vboxautostart.plist \
    /Library/LaunchDaemons

Backslashes for readability :-).

Edit /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist and set Disabled to false.

Create the file /etc/vbox/autostart.cfg with the following content:

default_policy = deny
david = {
    allow = true
    startup_delay = 10
}

Change david to match your MacOS username ($ whoami).

Next, get a list of VMs on the system:

$ VBoxManage list vms
"Fedora Server" {GUID for server displayed here}

For each server that you want to automatically start, enable autostart, configure the autostop-type method, and enable headless mode.

VBoxManage modifyvm "Fedora Server" --autostart-enabled on
VBoxManage modifyvm "Fedora Server" --autostop-type acpishutdown
VBoxManage modifyvm "Fedora Server" --defaultfrontend headless

Finally, test the configuration by running:

sudo launchctl load /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist
@superman-lopez
Copy link

Thanks, this works very well for me. I wonder: on macOS should we touch /etc for these kind of non-Apple configuration files? Would it be more appropriate to use for example /Library/Application Support/VirtualBox as the location for autostart.cfg?

@flease
Copy link

flease commented Jun 16, 2019

Thanks! Works on Mojave for me.

@jjknudsen
Copy link

jjknudsen commented Jun 30, 2019

So this works great for automatically starting the VMs, but as far as I can tell it still won't do a graceful shutdown of the guest. The Mac reboots just fine, but it's just killing the guest and then restarting as opposed to a graceful shutdown. I've tried both acpishutdown and savestate and neither seems to work.

I should add that I can do a an acpishutdown just fine from the GUI and the guest will shutdown gracefully.

Any ideas? I'm running Mac OS Mojave.

@mortenmathiasen
Copy link

I just made it work nice and easily with MacOS High Sierra 10.13.6 and VirtualBox 6.0.10
Thank you!

@freddan-teamleader
Copy link

freddan-teamleader commented Oct 10, 2019

I get the following error: VBoxAutostart: error: User is not allowed to autostart VMs
Running on Sierra

@jfrux
Copy link

jfrux commented Jan 2, 2020

Sounds like you may have forgot to change david = { } to your username first.

@jfrux
Copy link

jfrux commented Jan 2, 2020

Worked for me on an older Mac Mini running MacOS Sierra

@paulbeard
Copy link

paulbeard commented Feb 14, 2020

It doesn't seem to work on VBox v6.x. It doesn't see VMs from earlier versions so I can't autostart things it doesn't know about.

VBoxManage registervm FreeBSD10.vbox

VBoxManage: error: Runtime error opening '/var/root/Library/VirtualBox/FreeBSD10.vbox' for reading: -102 (File not found.).
VBoxManage: error: /Users/vbox/tinderbox/6.0-mac-rel/src/VBox/Main/src-server/MachineImpl.cpp[497] (nsresult Machine::initFromSettings(VirtualBox *, const com::Utf8Str &, const com::Guid *))
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component MachineWrap, interface IMachine, callee nsISupports
VBoxManage: error: Context: "OpenMachine(Bstr(a->argv[0]).raw(), machine.asOutParam())" at line 86 of file VBoxManageMisc.cpp

Looks to me like someone hardcoded a path. Even I know that's a Bad Idea. Should be able to pass a .vbox file as an argument and the binary work out the path or ask for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment