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