Start VMs at boot (new in 4.2.0)

Discussions related to using VirtualBox on Solaris hosts.

Start VMs at boot (new in 4.2.0)

Postby varboxer » 14. Sep 2012, 12:07

Hi

New in 4.2.0 is the ability to start VMs at boot.

Code: Select all   Expand viewCollapse view
svccfg -s svc:/application/virtualbox/autostart:default setprop config/config=/etc/vbox/autostart.cfg
svcadm enable svc:/application/virtualbox/autostart:default


But what is in the configuration file /etc/vbox/autostart.cfg?
The only thing documented is user permissions default_policy=deny and username { allow=true }

How do we configure which VMs are started by which users at boot?
varboxer
 
Posts: 22
Joined: 29. Mar 2011, 12:29
Primary OS: Solaris
VBox Version: OSE other
Guest OSses: Solaris, Ubuntu

Re: Start VMs at boot (new in 4.2.0)

Postby naidod » 20. Sep 2012, 07:19

Yep, some of the new 4.2.0 features - as nice as they are - seem to be thinly documented thus far. I assume you've looked at the relevant section of the VirtualBox 4.2.0 manual? This is what I did to get autostart working on a Solaris 11 host - all of the commands were entered from a terminal running as my Virtualbox user, any regular user account that you want to run Virtualbox VMs under will do:

Code: Select all   Expand viewCollapse view
sudo mkdir /etc/vbox
sudo chown <myvboxuser>:<myvboxusersgroup> /etc/vbox #I'm not sure if this is strictly necessary but I did it anyway. You might be fine editing this file as root and leaving the permissions as is - do any experts know what unix best practice is in this regard?
nano -w /etc/vbox/autostart.cfg #Add the contents of autostart.cfg here, see below for the contents of the file.
svccfg -s svc:/application/virtualbox/autostart:default setprop config/config=/etc/vbox/autostart.cfg


It's worth noting that you do not have to place your autostart.cfg at /etc/vbox/autostart.cfg. This is just the default location used in the /opt/VirtualBox/smf-vboxautostart.sh script. If you want to place the configuration file somewhere else then make sure you tell the autostart service about it using the svccfg command (see above).

Now to configure which VMs are started by which users at boot, use the VBoxManage modifyvm utility working from the terminal as the user you want to run the VM under at boot:

Code: Select all   Expand viewCollapse view
VBoxManage modifyvm <yourvirtualmachinename> --autostart-enabled on
#You can also set a delayed start for the vm using the command: VBoxManage modifyvm <yourvirtualmachinename> --autostart-delay <delayinseconds>


Remember to enable the Virtualbox autostart service:

Code: Select all   Expand viewCollapse view
svcadm enable svc:/application/virtualbox/autostart:default


I found that had my VirtualBox VMs starting automatically at boot. I don't have everything working properly so far though. For some reason, the autostart service transitions into maintenance mode after starting all the VMs. The log file shows:

VirtualBox Autostart 4.2.0 r80737 solaris.amd64 (Sep 13 2012 07:10:25) release log
00:00:00.000585 main Log opened 2012-09-19T16:07:20.626689000Z
00:00:00.000592 main OS Product: SunOS
00:00:00.000594 main OS Release: 5.11
00:00:00.000596 main OS Version: 11.0
00:00:00.000678 main Executable: /opt/VirtualBox/amd64/VBoxAutostart
00:00:00.000679 main Process ID: 4738
00:00:00.000681 main Package type: SOLARIS_64BITS_GENERIC
[ Sep 20 02:07:20 Method "start" exited with status 0. ]
[ Sep 20 02:07:30 Stopping because all processes in service exited. ]
[ Sep 20 02:07:30 Executing stop method (:kill). ]
[ Sep 20 02:07:30 Restarting too quickly, changing state to maintenance. ]


I'll be investigating this further today and will post when I find a solution.

Another thing I'm curious about is the --autostop-type property which is listed an a setting for the VBoxManage modifyvm command. The options are:

Code: Select all   Expand viewCollapse view
[--autostop-type disabled|savestate|poweroff|acpishutdown]


It would make sense for us to be able to set this so we can determine how our virtual machines are brought down upon shutdown, and also when we disable the autostart service. When attempting to set this option however, this is what I get:

Code: Select all   Expand viewCollapse view
<myvboxuser>@<mydomain>:~$ VBoxManage modifyvm pfsense --autostop-type savestate
VBoxManage: error: The VM autostop feature is not supported on this platform
VBoxManage: error: Details: code VBOX_E_NOT_SUPPORTED (0x80bb0009), component SessionMachine, interface IMachine, callee nsISupports
VBoxManage: error: Context: "COMSETTER(AutostopType)(enmAutostopType)" at line 2447 of file VBoxManageModifyVM.cpp


Can anyone with VirtualBox expertise comment as to whether we are intended to use this autostop option under Solaris 11?
naidod
 
Posts: 1
Joined: 20. Sep 2012, 06:44

Re: Start VMs at boot (new in 4.2.0)

Postby varboxer » 20. Sep 2012, 11:49

Thanks for your hints :)

"modifyvm --autostart-enabled on" isn't mentioned in the autostart section of the manual and isn't documented in the VBoxManage section :(

The problem with setting an autostop policy makes the whole thing useless though :(
varboxer
 
Posts: 22
Joined: 29. Mar 2011, 12:29
Primary OS: Solaris
VBox Version: OSE other
Guest OSses: Solaris, Ubuntu

Re: Start VMs at boot (new in 4.2.0)

Postby aeichner » 16. Oct 2012, 11:56

The problem with the autostart service going into maintenance mode will be fixed in the next maintenance release, thanks for the hint!
Autostop does not work because we couldn't finish it in time for 4.2. The API to configure it is already there to make it possible to ship it in a future 4.2.x release if we think the risk is low enough to break something else. That the option appears in VBoxManage already is a bug which will be fixed in the next maintenance release too.
aeichner
Oracle Corporation
 
Posts: 149
Joined: 31. Aug 2007, 19:12

Re: Start VMs at boot (new in 4.2.0)

Postby immo » 25. Feb 2013, 01:26

Are there any news regarding the autostop function ?

It would be quite useful ;-) Are there any workarounds proposed ? My linux VMs are not able to be restarted automatically if they are not shutded down correctly...

Immo
immo
 
Posts: 7
Joined: 25. Feb 2013, 01:22

Re: Start VMs at boot (new in 4.2.0)

Postby apexio » 16. May 2013, 23:20

In CentOS, create a text file called: /etc/init.d/vbox

Code: Select all   Expand viewCollapse view
chmod 755 /etc/init.d/vbox


Paste in the code:

Code: Select all   Expand viewCollapse view
#!/bin/sh
#chkconfig: 2345 40 60
#description: VirtualBox


start()
{

echo -n "Starting VM01"
/usr/bin/VBoxManage startvm "VM01" --type headless

echo -n "Starting VM02"
/usr/bin/VBoxManage startvm "VM02" --type headless

}

stop()
{

echo -n "Saving VM VM01 State..."
/usr/bin/VBoxManage controlvm "VM01" savestate

echo -n "Saving VM VM02 State..."
/usr/bin/VBoxManage controlvm "VM02" savestate

}


case "$1" in
  start)
        start
   ;;
  stop)
          stop
   ;;
  restart|reload)
        stop
   start
   ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac

exit 0



This will automatically start all vms at boot, and also stop them all if you issue a shutdown command on the server.

You can also issue start, stop, or restart on the command line like this:

Code: Select all   Expand viewCollapse view
/etc/init.d/vbox start
apexio
 
Posts: 1
Joined: 16. May 2013, 23:14

Re: Start VMs at boot (new in 4.2.0)

Postby _Thomas_ » 26. Oct 2013, 22:34

I have created a bug report of this issue: https://www.virtualbox.org/ticket/12262
_Thomas_
 
Posts: 2
Joined: 21. Sep 2012, 07:53

Re: Start VMs at boot (new in 4.2.0)

Postby tischler » 25. May 2014, 10:44

suse linux 13.1
an easy way to start a vm is to write a script like:

#! /bin/sh
#
#Start einer Virtualbox
sleep 30
VBoxManage startvm name_of_VM

name it
add it to autostart (alt F2)
Thats it
tischler
 
Posts: 1
Joined: 25. May 2014, 10:16


Return to VirtualBox on Solaris Hosts

Who is online

Users browsing this forum: No registered users and 54 guests