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.
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:
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:
You might get an error message:
Failed to create service VBoxVmService: The specified service already exists.
If so, just uninstall and reinstall the service:
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:
- Right-click the System Tray icon.
- Go to each VM listed and select "Stop".
- After stopping each VM, select "Stop VBoxVmService".
- 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!