/usr/home

just some random thoughts

Autostart and stop Virtualbox VMs on a Solaris 10+ hosts

It’s a verry annoing thing, that Virtualbox hasn’t implemented a function to start and stop the VMs when the hosts is going down. The problem is, that if you poweroff your host and forget to shutdown all your VMs they will be simply killed. Because of this, man people created scripts to do this but most of them are only useable on windows or linux – for me they didn’t worked for solaris (possibly because of the SMF init-system).

Now I found a solution: vboxsvc

This project includes:

  • vbox-svc.xml (SMF-File for using with SVC)
  • vbox.sh (script which is a wrapper between SVC and VBoxManage)
  • vbox-delay-on-boot.xml (script to delay the start of the machines a bit, so your host has enough time to start all of it’s services bevore the VMs are started, didnt’ worked for me on OpenIndiana 151a4)

Configuration

edit vbox-svc.xml located in /lib/svc/manifest/site/:
There are lots of options you can use, but i will only explain the necessary ones. The rest is well documented and should be easy to use.

search fot this line:

<instance name="VM_NAME" enabled="false">

here you change VM_NAME to the name of your VM and set enable to true, but be careful: you cannot use spaces in the name! Add a line for every VM you want to control!

if your virtualbox isn’t running under the root account you must change these line:

<method_credential user="root" group="root" />

now import your manifest using:

svccfg import vbox-svc.xml

after every change to the vbox-svc.xml file you have to delete the smf-entry and reimport the file!

svccfg delete svc:/site/xvm/vbox:<vmname>

Using vboxsvc:

like every other svc entry you can use

svcadm enable <vmname>

and

svcadm disable <vmname>

if you use disable then the machinestate is saved insted of turning the machine off, you can change this behaviour in the vbox-svc.xml file!

That’s it! Now your Virtualbox machines are started and stopped depending on what you host does.