Virtualbox 4.2 VM autostart on Debian Squeeze

Posted by on December 28, 2012

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.

4 Responses to Virtualbox 4.2 VM autostart on Debian Squeeze

  1. phil

    Hello,

    i got a problem with your “howto” at my Debian Squeeze Server.

    I follow your instructions and at the point of setting the VM to autostart i got an error.

    What i do: e.g:

    my vm is named ns2:

    so i run the commend in the shell: “VBoxManage modifyvm ns2 –autostart-enabled on”

    But the following error appears:

    VBoxManage: error: Adding machine ‘ns2′ to the autostart database failed with VERR_ACCESS_DENIED
    VBoxManage: error: Details: code NS_ERROR_UNEXPECTED (0x8000ffff), component SessionMachine, interface IMachine, callee nsISupports
    VBoxManage: error: Context: “COMSETTER(AutostartEnabled)(ValueUnion.f)” at line 2422 of file VBoxManageModifyVM.cpp

    Hope you can help me dude.

    best regards phil

  2. David Goodwin

    You need to run the command as the same system user who is running the virtual machines.

    If you are then I suspect your file permissions are wrong somewhere.

    David

  3. Marcelo

    Worked like a charm, I changed the user and location to my user, and had no issues at all.
    I was using the hackish VBoxManage command, placed in the rc.local.

  4. Ion

    phil,
    I had the same problem and found the solution on another blog.
    assuming your virtual machine will be started by the vbox user and you did all the steps before
    vbox@machine $ VBoxManage modifyvm ns2 –autostart-enabled on
    run this
    rootorsudo@machine # chgrp vboxusers /etc/vbox
    rootorsudo@machine # chmod 1775 /etc/vbox

    then run your
    vbox@machine $ VBoxManage modifyvm ns2 –autostart-enabled on

    David, thanks for your article

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>