Jump to content


  • 0
hybrid

Have VirtualBox VMs Start as a Service on a Windows Host

Question

While this isn't strictly 'Microsoft Application Virtualization', I came across a problem where I wanted to run VirtualBox on a Windows Server 2008 R2 host, and have the virtual machines started automatically when the machine boots.

 

(Hyper-V is great, I'm sure, but we went with VirtualBox for this particular solution as we were running a Linux distribution that is very picky about its virtualised hardware requirements, and is unfortunately very old -- Cisco Eagle Server <pdf link, 1.5MB> for teaching the CCNA courses).

 

In order to get the VirtualBox VM to start upon boot, it needs to be installed as a service, with an extra piece of software called VBoxVmService. Here's how to set it up:

 

1.

 

Install VirtualBox as normal, and create your new virtual machine as normal as well -- running through the install process. Once everything is running fine, you'll probably want to enable VRDP/VRDE on the virtual machine's settings, so you can access it over RDP.

 

Once VirtualBox is running as a service, you can't use the VirtualBox application to control the virtual machine, so VRDP is the ideal solution. (Or for Linux guests where you only need access to the command line, configure an SSH server for remote login on the guest before you move to the next step).

 

2.

 

Install VBoxVmService into C:\vms.

 

We first need to edit the INI file in this folder with the information to install the service:

 

[settings]
  ServiceName=VBoxVmService
  VBOX_USER_HOME=C:\Users\Administrator\.VirtualBox
  RunAsUser=.\Administrator
  UserPassword=enteryourpasswordhere
  RunWebService=no
  PauseShutdown=5000
[Vm0]
  VmName=name of the vm in VirtualBox
  ShutdownMethod=savestate
  AutoStart=yes

 

Substitute in the VBOX_USER_HOME with the .VirtualBox folder in the correct user's home directory, as well as the RunAsUser and UserPassword directives, and set the name of the target virtual machine in the VirtualBox app in VmName.

 

You can also add additional [Vmx] sections after [Vm0] with other virtual machines to start when the machine boots.

 

When you are happy with your configuration, from an Administrator-enabled Command Prompt, run:

 

C:\vms\VmServiceControl.exe -i

 

to install the service. Once the service is installed, you can remove your user password from the INI file, as it is saved in the Service configuration.

 

If the RunAsUser you have entered does not have the Log on as a service right, you need to grant that right to the user, or the service will not be able to start. The easiest way to do this is to go to Start > Run > services.msc, find VBoxVmService and edit it. On the Log On tab, re-enter the user's password and click OK. You will get a notification that the relevant right has been granted.

 

3.

 

Now, you must reboot the computer before attempting to start the service for the first time, or it will be unable to locate the VMs.

 

4.

 

Upon reboot, the service should start (subject to the 'Automatic (Delayed Start)' delay) and your VMs will be started upon boot.

 

You may wish to edit the Service to set the startup type to Automatic to avoid this delay.

 

At any time, you can uninstall the service with:

 

C:\vms\VmServiceControl.exe -u

 

Also, if you want to make any changes to the service, you must edit the INI file, uninstall the service as above, reboot, reinstall the service and reboot again. It is annoying, yes, so hopefully you don't have to make changes too often. ;)

 

That's it! We now have the VBoxVmService starting the selected VirtualBox virtual machines at system startup, without the need for anyone to interactively log in.

Share this post


Link to post
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.