Skip to content

Instantly share code, notes, and snippets.

Created July 19, 2013 20:13
Show Gist options
  • Save reidransom/6042016 to your computer and use it in GitHub Desktop.
Save reidransom/6042016 to your computer and use it in GitHub Desktop.
Auto-starting VirtualBox VMs on OS X

Auto-starting VirtualBox VMs on OS X

After finding a lot of other posts on the topic that didn't work out for me this one did the trick so I'm reposting for my own sense of self preservation.

Link to original article.

Copy the Virtualbox autostart plist template file to your system's LaunchDaemons folder.

sudo cp \
    /Applications/ \

Then edit /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist set Disabled to false, set KeepAlive to true, and confirm the last string entry in the command array is set to /etc/vbox/autostart.cfg. The file should look like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Make the directory /etc/vbox and create the file /etc/vbox/autostart.cfg with the following content:

default_policy = deny
osxusername = {
allow = true

Make sure to change osxusername to the username on your system that the VMs are under.

Next properly set permissions:

sudo chmod +x /Applications/
sudo chown root:wheel /etc/vbox
sudo chown root:wheel /etc/vbox/autostart.cfg
sudo chown root:wheel /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist

Now, configure the VMs that should automatically start and set how they should be stopped:

VBoxManage modifyvm vmname --autostart-enabled on
VBoxManage modifyvm vmname --autostop-type acpishutdown

Finally, test the configuration by running:

sudo launchctl load /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist

After a reboot, the VMs that have been set with autostart enabled should be running!


Copy link

For those that like to automate to setup, following ansible tasks will configure MacOS host

    - name: vm autostart config exists
        path: /etc/vbox
        state: directory
        recurse: true
      become: true

    - name: vm autostart config
        dest: /etc/vbox/autostart.cfg
        content: |
          default_policy = deny
          {{ ansible_user_id }} = {
          allow = true
      become: true

    - name: get vm autostart plist
        xmlstring: "{{ lookup('ansible.builtin.file', '/Applications/') }}"
        xpath: /plist/dict/key[.='Disabled']/following-sibling::*[1]
        state: absent
      register: autostart_xml

    - name: vm autostart plist, enable
        xmlstring: "{{ autostart_xml.xmlstring }}"
        xpath: /plist/dict/key[.='Disabled']
        insertafter: true
          - "false"
      register: autostart_xml

    - name: vm autostart plist
        dest: /Library/LaunchDaemons/org.virtualbox.vboxautostart.plist
        content: "{{ autostart_xml.xmlstring }}"
      become: true

I'm using vagrant to create my vm. Following excerpt will set vm properties

Vagrant.configure("2") do |config|
  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--autostart-enabled", "on"]
    vb.customize ["modifyvm", :id, "--autostop-type", "poweroff"]

This works with VirtualBox 6.1

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