Categories TutorialsVirtualBox

How to start VirtualBox machines automatically as a service

You might be familiar with VirtualBox, a free and open-source software package for running virtual PCs on a host machine. It was developed by Oracle and can be installed on Windows, Macintosh, Linux, and Solaris hosts.

Supported guest operating systems, those running virtually inside the “box,” include DOS, just about every Windows version since NT 4.0, major Linux kernel versions, Solaris, and OpenSolaris, OS/2, and OpenBSD. Others probably work too. Setting up VirtualBox 5.0 is a fairly simple process, and is largely unchanged from earlier versions that have been covered here before.

There remains one glaring omission in this otherwise excellent Hypervisor product, however. To spot it, just check chapter 9, section 24 of its online manual:

Starting with VirtualBox 4.2.0 it is possible to start VMs automatically during system boot on Linux, Solaris and Mac OS X for all users.

That’s right, there’s no option to automatically launch your virtual machines on a Windows host. Server reboots? Sorry, your virtual machines are still turned off. Better go log in and boot them all up again.

Luckily, there are a couple third-party solutions to this problem. This article will cover VBoxVmService, a trusty helper I’ve used for the past couple years in a live Windows server environment.

Configure your virtual machines

Before doing anything with VBoxVmService, set up all your virtual machines the way you like them. Oracle’s VirtualBox Manual has pretty good instructions (if distressingly few screenshots). Modifying any one VM after VBoxVmService is running is a tiny bit of a hassle, so choose settings that won’t need to be changed often.

All set? Okay then.

Download & Install VBoxVmService

Head on over to VBoxVmService’s Sourceforge page and click the main image to download the EXE installer. Run the executable for a very standard wizard, which places all its files in C:\vms by default. Head to that directory to find a nice little list of files.

We’re mostly concerned with the INI file, since that’s where all our settings go. Open it up in Notepad or your preferred text editor to see its initial state.


[Settings]
VBOX_USER_HOME=C:\Users\John\.VirtualBox
RunWebService=no
PauseShutdown=5000

[Vm0]
VmName=ubuntu
ShutdownMethod=savestate
AutoStart=yes

[Vm1]
VmName=winxp
ShutdownMethod=savestate
AutoStart=no

Configure the INI

The VBOX_USER_HOME variable is probably fine as-is if you installed VirtualBox and VBoxVmService with their default settings. The path is not the same (necessarily) as the Default Machine Folder set within the Preferences of Oracle VM VirtualBox Manager.

RunWebService controls whether or not to start VirtualBox’s HTTP web service automatically, so only change that to “yes” if you need it. PauseShutdown allows extra time, in milliseconds, for VMs to gracefully shut down if the host machine is shut down.

  • You will have to pay attention to the rest. [Vm0] and [Vm1] show sample values for:
  • the name of each of your VMs (VmName)
  • how VMs should react when told to stop (ShutdownMethod, either “savestate” for a quick session snapshot or “acpipowerbutton” for a full shutdown), and
    whether or not to boot when VBoxVmService starts (AutoStart)

The first thing to do is to replace the VmName with the name of your VM(s). If you only have one, remove everything from [Vm1] on. If you have more than two, add more sections with the same format starting with [Vm2], then [Vm3], etc.

Depending on your user permissions, you might also need to add two lines granting the service access to the VBOX_USER_HOME directory. Put them in the [Settings] section:


RunAsUser=.\yourusername
UserPassword=yourpassword

Don’t worry, that cleartext password is only there very briefly. You can delete those lines immediately after installing the service.

Save VBoxVmService.ini and then open a command prompt as Administrator. Run the following command, which installs the service:

C:\vms\VmServiceControl.exe -i

You might get an error message:

Failed to create service VBoxVmService: The specified service already exists.

If so, just uninstall and reinstall the service:

C:\vms\VmServiceControl.exe -u
C:\vms\VmServiceControl.exe -i

In fact, any time you change something in VBoxVmService.ini, you’ll need to uninstall and reinstall the service. Adding or removing a VM, altering a VM’s AutoStart or ShutdownMethod, or tweaking the PauseShutdown time will require this procedure.

It’s not a bad idea to reboot either.

Control the VirtualBox service

Back in the C:\vms folder, open VmServiceTray.exe to get a handy little icon near your clock that allows you to start and stop VBoxVmService, as well as any individual VMs. Create a shortcut and place it in the Startup folder to always have it on hand at boot.

You should be able to open the VirtualBox GUI with the service and VMs still running, but that wasn’t always the case. Versions 4.2 and 4.3 of the GUI wouldn’t open while VBoxVmService was started, so to make any modifications or add new VMs, the service (and therefore all running VMs) had to be stopped. If that issue pops up for you in version 5, take the following steps before opening the GUI:

  1. Right-click the System Tray icon.
  2. Go to each VM listed and select "Stop".
  3. After stopping each VM, select "Stop VBoxVmService".
  4. Wait about 10 seconds and open the Oracle VM VirtualBox GUI.

You can now make changes to the VMs and open them interactively. When you’re done, close the VMs, close the VirtualBox GUI, and restart the service and each VM via the System Tray icon. Again, this shouldn’t be necessary with version 5, but it can’t hurt to be prepared.

Access your virtual machines

Once started through VBoxVmService, your virtual machines can be used like any other remote machine - via Remote Desktop, VNC software, LogMeIn, TeamViewer, or whatever your preferred solution is.

Even though the Oracle VM VirtualBox Manager can be opened while your VMs are running under VBoxVmService, their state won’t be correctly reflected in that GUI. Try to start one that says it’s powered off and you’ll get a nasty error box containing multiple failures. You can stop the relevant VM through the System Tray icon if “ShutdownMethod” in your VBoxVmService.ini file is set to “acpipowerbutton”; if it’s “savestate”, though, you’re better off remoting into the VM and shutting it down properly.

For advice and hacks related to earlier versions, the VBoxVmService wiki is a good place to start. Happy virtualizing, and let us know your experiences!

jaQ Andrews

John "jaQ" Andrews is the Information Manager for custom app development company Zco Corporation. He also runs Defunct Comic and his own blog between binging Netflix, brushing his cats, and writing tech columns for The Hippo.

Share
Published by
jaQ Andrews

Recent Posts

Top 7 open source intelligence tools lighting it up in 2019

As open source becomes the norm, open source intelligence tools are in demand. Here are a few that are already…

9 hours ago

Land of the dinosaurs: Is CapEx IT about to go extinct?

As businesses head to the cloud, will CapEx IT be a thing of the past? Or will there always be…

14 hours ago

Exchange DAG: Set it up before a disaster takes you down

Don’t be this IT admin: Disaster hits and all you can say is, “I should have set up a database…

17 hours ago

8 tips for protecting online privacy and maintaining anonymity

In protecting online privacy, the actions you take are far more important than any legal framework that could be put…

3 days ago

Cryptomining arrest only the start of problems for these nuke plant workers

Cryptomining on the job behind the boss’s back is bad enough, but when the employees work in a nuclear power…

4 days ago

Does it make sense to purchase a lifetime VPN subscription?

Cybersecurity experts recommend setting up a VPN to secure your data and privacy. But is purchasing a lifetime VPN subscription…

4 days ago