Sunday, November 30, 2014

How To AutoStart Virtual Machines in Linux

How To AutoStart Virtual Machines with Virtual Box 4.3 in Linux

After much frustration with incomplete blog Posts, this guide works with full instructions on how to get one or multiple VM's running on boot just as root. This guide will start your VM's as the root user. Therefore this guide will automatically boot from the root user of which may be casue for concern based on your environment.
Hopefully this will help anyone looking for a fully working solution.
This guide was based on VirtualBox 4.3 installed on Debian 7.


Firstly, you need to create/edit 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. The file should look similar to this:

root@home:~ nano /etc/default/virtualbox add to the end

# virtualbox defaults file
VBOXAUTOSTART_DB=/etc/vbox
VBOXAUTOSTART_CONFIG=/etc/vbox/autostart.cfg

Now we need to create the autostart  config file.
root@home:~ nano /etc/vbox/autostart.cfg  and add..

# Default policy is to deny starting a VM, the other option is "allow".
default_policy = allow
# Create an entry for each user allowed to run autostart
root ={
allow = true
startup_delay = 1
}

Set permissions on directory to the vboxuser group and make sure users can write to the directory as well as sticky bit.

root@home:~ sudo chgrp vboxusers /etc/vbox
root@home:~ sudo chmod 1775/etc/vbox



MAKE SURE YOU ARE LOGGED IN AS ROOT - SUDO IS NOT GOOD ENOUGH! or do sudo -s

root@home:~ VBoxManage setproperty autostartdbpath /etc/vbox
root@home:~ VBoxManage modifyvm windows7 --autostart-enabled on

root@home:~ touch /etc/vbox/root.start
root@home:~ chmod 777 /etc/vbox/root.start

root@home:~ nano /etc/rc.local and add the lines

/etc/init.d/vboxdrv start
/etc/init.d/vboxautostart-service start

place these BEFORE the "exit 0"

reboot and you should be set to go!
Good Luck!

No comments:

Post a Comment