There’s the great FreeNAS jail phpVirtualBox. It lets you run headless VirtualBox-machines on your FreeNAS server, in case you need a different operating system than FreeBSD. I’m using it to run Icinga and Musicbrainz. There’s only one problem: After a server reboot (yes, that happens) the VMs do not automatically start again.
Luckily there’s a method to to achieve that.
First you’ll have to connect to your FreeNAS (and the Virtualbox-jail) on the shell. If you don’t know how to do it, have a look here. After connecting its just a matter of editing one file: the rc.conf.
The file rc.conf contains descriptive information about the local host name, configuration details for any potential network interfaces and which services should be started up at system initial boot time.
To edit the rc.conf, enter the following command on the shell:
edit /etc/rc.conf
Then you have to put the following code into the now open file (copy&paste it). You’ll have to replace “yourm” with the name of your virtual machine.
# this is required for networking (replaces loading remaining modules manually)
vboxnet_enable="YES"
# start VirtualBox
vboxheadless_enable="YES"
# VMs to start (whitespace-separated list):
vboxheadless_machines="yourvm"
# definition for VM with acronym "yourvm":
vboxheadless_yourvm_name="yourvm"
vboxheadless_yourvm_user="vbox"
vboxheadless_yourvm_stop="savestate"
Press escape then Enter twice to save and exit the file.
If you want to add another virtual machine, simply add it to the vboxheadless_machines-list and append the three following lines, again replacing the name.
Here’s an example where two virtual machines are automatically started at boot:
# VMs to start (whitespace-separated list):
vboxheadless_machines="icinga musicbrainz"
# definition for VM with acronym "icinga":
vboxheadless_icinga_name="icinga"
vboxheadless_icinga_user="vbox"
vboxheadless_icinga_stop="savestate"
# definition for VM with acronym "musicbrainz":
vboxheadless_musicbrainz_name="musicbrainz"
vboxheadless_musicbrainz_user="vbox"
vboxheadless_musicbrainz_stop="savestate"
That is all you have to do. Next time your FreeNAS server reboots, the VMs will start, too!