1. Modify the file /etc/default/virtualbox and add a few variables.

VBOXAUTOSTART_DB which contains an absolute path to the autostart database directory and
VBOXAUTOSTART_CONFIG which contains the location of the autostart config settings.


echo 'VBOXAUTOSTART_DB=/etc/vbox' | sudo tee -a /etc/default/virtualbox
echo 'VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg' | sudo tee -a /etc/default/virtualbox

2. Create the autostart.cfg file
NB: You may need to change the username or add others, depending on your installation.

echo '# Default policy is to deny starting a VM, the other option is "allow".' | sudo tee /etc/vbox/autostart.cfg
echo 'default_policy = deny' | sudo tee -a /etc/vbox/autostart.cfg
echo '# Create an entry for each user allowed to run autostart' | sudo tee -a /etc/vbox/autostart.cfg
echo 'vbox = {' | sudo tee -a /etc/vbox/autostart.cfg
echo 'allow = true' | sudo tee -a /etc/vbox/autostart.cfg
echo '}' | sudo tee -a /etc/vbox/autostart.cfg

If you are the only user you can just add the line default_policy = allow to the autostart.cfg file.

3. Clean up permissions
Set permissions on directory to the vboxuser group and make sure users can write to the directory as well as sticky bit.
sudo chgrp vboxusers /etc/vbox
sudo chmod 1775 /etc/vbox

Add each of the users to the vboxusers group.
sudo usermod -a -G vboxusers USERNAME
(replace USERNAME with the username)
NOTE: If you have changed group permissions for the current user, log out and back in again to refresh the permissions.

4. Create start/stop files
cd /etc/vbox
sudo touch vbox.start
sudo touch vbox.stop

And change owner with:
sudo chown vbox:vboxusers vbox.start
sudo chown vbox:vboxusers vbox.stop

4. Enable autostart/autostop
Every user who wants to enable autostart for individual machines has to set the path to the autostart database directory with

VBoxManage setproperty autostartdbpath /etc/vbox

and enable autostart/autostop for an individual VM with
NB: The VM needs to be shut down for this command
VBoxManage modifyvm gitlab --autostart-enabled on --autostop-type acpishutdown

NB: autostopo types: disabled, savestate, poweroff, acpishutdown
This will create a myuserid.start file in /etc/vbox directory

Now restart the vboxautostart-service to read in the changes.
sudo service vboxautostart-service restart

5. Reboot and test
Reboot your system and your VM(s) should start