Headless VirtualBox as Server VMs on Solaris x86 Host

I use VirtualBox a lot on both my desktop and to run a few server type VMs like an email collection server, Minecraft server for the kids and a few others. The one issue I had with running VirtualBox on the server is that it wasn’t REALLY intended to be a server virtualization platform. But I liked using VirtualBox since I can easily move VM around. So I started a quest to find out a way to have VirtualBox automatically start VMs on my Solaris x86 NAS PC.  As I mentioned in an earlier post, I use Solaris x86 as my server/nas OS purely because of the outstanding ZFS.

I came across a great tool at http://sourceforge.net/projects/vboxsvc/ that provided just what I needed. It also does way more than I’ll use at home.

The following steps assume that you already created your VMs using VirtualBox.  These steps will just add it to the vboxsvc program.

Install VirtualBox SMF service (run as root)
root@nas# gzcat COSvboxsvc-0.16.pkg.gz > /tmp/x
root@nas# pkgadd -d /tmp/x -G

Create a smf XML file for your VM (run as local user).
admin@nas$ cp /var/svc/manifest/site/vbox-svc.xml ~/vbox-mail-svc.xml

Edit your new file and change the 3 parameters to match your installation and your VM name.  Find this section,
        <instance name='VM_NAME' enabled='false'>
                <method_context working_directory='/var/tmp'>
                        <method_credential user='root' group='root' />
                </method_context>

and change it to look something like this.  For me, the VM in VB is called ‘mail’, with VB running as my local user called ‘admin’, which is in the ‘vboxuser’ group.

        <instance name='mail' enabled='false'>
                <method_context working_directory='/var/tmp'>
                        <method_credential user='admin' group='vboxuser' />
                </method_context>

Import and start the VM (run as root)
root@nas# svccfg import vbox-mail-svc.xml
root@nas# svcs -a | grep -i xvm
disabled       Jan_04   svc:/site/xvm/vbox:mail
root@nas#
svcadm enable mail

root@nas# svcs -a | grep -i xvm
online         Jan_04   svc:/site/xvm/vbox:mail

Your VM should now be running.  If you have the VirtualBox Manager window open, you can see it starting in the preview window.

A few notes on how to use it.  I created a few aliases for each VM I add that will be  useful.  These alias are for the non-root user that the VMs are actually running as.  My aliases look something like the following for each VM I have.

alias showmail="/lib/svc/method/vbox.sh -svc svc:/site/xvm/vbox:mail startgui"
alias startmail="/lib/svc/method/vbox.sh -svc svc:/site/xvm/vbox:mail start"

‘showmail’ will ‘Save the machine state’ the VM and the automatically start it back up in a GUI so that you can interact with the console window.  When you are done with the console and want to send it back into headless mode, just click on the close window button and choose to ‘Save the machine state’.  Once the VM has been saved, vboxsvc will automatically start it back up in the headless mode.

‘startmail’ is just a simple alias that will start the VM in headless mode if the VM is not actually started yet.

So for each new VM you want to add to the vboxsvr, just copy the SMF file you created, change the name of the VM and import the SMF .  Then just create a few more aliases.

alias showminecraft="/lib/svc/method/vbox.sh -svc svc:/site/xvm/vbox:minecraft startgui"
alias startminecraft ="/lib/svc/method/vbox.sh -svc svc:/site/xvm/vbox:minecraft start"

There is a lot more create details at the website listed above.
This post ‘VirtualBox as Server VMs on Solaris x86 Host’ first appeared on https://gregorygee.wordpress.com/.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: