Skip to content

CentOS 7 VirtualBox vboxautostart-service setup with systemd

These notes were written on CentOS Linux release 7.3.1611 running Oracle VirtualBox 5.1.14. Our goal is to get a virtual machine running automatically at boot under systemd.

VirtualBox’s documentation about this isn’t bad. But it’s also not quite complete. Hopefully this post will help clear up some issues.

From Oracle’s documentation:

On Linux, the VirtualBox autostart service is activated by setting two variables in /etc/default/virtualbox. The first one is VBOXAUTOSTART_DB which contains an absolute path to the autostart database directory. The directory should have write access for every user who should be able to start virtual machines automatically. Furthermore the directory should have the sticky bit set. The second variable is VBOXAUTOSTART_CONFIG which points the service to the autostart configuration file which is used during boot to determine whether to allow individual users to start a VM automatically and configure startup delays.

So what should the values be in that file /etc/default/virtualbox? For my setup values of

VBOXAUTOSTART_DB=/etc/vbox
VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg

worked well. Using /etc/vbox/vbox.cfg as suggested in many documents did not work. For some reason the shell script’s to start the VM’s attempted to execute the lines in the file, rather than reading the configuration values. Simply renaming it should do the trick, and setting the correct value in /etc/default/virtualbox.

The example configuration file given in the VirtualBox documentation worked for me. You’ll just need to change the user id’s as required.

“The directory should have write access for every user who should be able to start virtual machines automatically” – In a normal setup, VirtualBox users are added to the vboxusers group. So you’ll probably want to do sudo chgrp vboxusers /etc/vbox assuming you’re saving the autostart database in /etc/vbox directory.

“Furthermore the directory should have the sticky bit set.” – The “sticky bit” is simply a security measure that doesn’t allow some users to write to files or directories, despite having the appropriate permissions. You can read more here. Assuming again that the configuration is in /etc/vbox, you’ll want to run something like sudo chmod 1775 /etc/vbox which will set the permissions appropriately.

“Every user who wants to enable autostart for individual machines has to set the path to the autostart database directory with
VBoxManage setproperty autostartdbpath ” – So in our case we simply run vboxmanage setproperty autostartdbpath /etc/vbox.

Finishing up

If you restart your machine now, you will notice no change. No boxes starting automatically. Okay, a couple of steps left that the Oracle folks left out of that section of the documentation. First, you'll need to check that the vboxautostart-service is enabled to run at start up. That can be done with a simple sudo systemctl enable vboxautostart-service followed by sudo systemctl start vboxautostart-service.

The key part left out, is how to set a particular VM to start on boot. This can be enabled with vboxmanage modifyvm {UUID-or-Name-of-VM-Here} --autostart-enabled on.

After that, run sudo systemctl restart vboxautostart-service and you should see your VirtualBox start up.

Spread The Love, Share Our Article

  • Delicious
  • Digg
  • Newsvine
  • RSS
  • StumbleUpon
  • Technorati
  • Twitter

Related Posts

Comments

There are no comments on this entry.

Trackbacks

There are no trackbacks on this entry.

Add a Comment

Required

Required

Optional


framework-break