One new feature of VirtualBox 4.2 is that it has support for auto-starting vm’s on bootup of the host server (via init etc). This means I can remove my hackish ‘su – vbox -c “VBoxHeadless –startvm VMName &”‘ additions in /etc/rc.local, and the VM’s will also hopefully be terminated gracefully on shutdown.
The docs/guides online which I could find were a bit cryptic, or incomplete, so here’s what I ended up doing :
Edit /etc/default/virtualbox and add in the following two lines :
VBOXAUTOSTART_DB=/etc/vbox VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg
Then create /etc/vbox/autostart.cfg with :
# See e.g. https://www.virtualbox.org/manual/ch09.html#autostart default_policy = deny vbox = { allow = true }
(My virtual machines run under a user called ‘vbox’).
Finally, set the VMs to autostart and so on – so as the user who the VMs should run as (in my case, vbox) run the following commands :
VBoxManage setproperty autostartdbpath /etc/vbox VBoxManage modifyvm NameOfVirtualMachine --autostart-enabled on VBoxManage modifyvm NameOfAnotherVirtualMachine --autostart-enabled on ....
Then, as root, run :
/etc/init.d/vboxautostart-service start
And you’ll then see your various VMs running.
Leave a Reply