How to run a headless VM with VBoxManager as a windows service
Objective
I want to run this command VBoxManage startvm MyVM --type headless
at the boot system just like a service (postgres, apache) does.
What i've tried
1. I've tried to create a service using sc command
I've found over the internet that could be the solution so i tried all this versions:
sc create "vboxMyVMService" binPath= "C:\Progman Files\Oracle\VirtualBox\VBoxManage.exe startvm MyVM --type headless"
sc create "vboxMyVMService" binPath= "C:\Progman Files\Oracle\VirtualBox\VBoxManage startvm MyVM --type headless"
No success, so i tried to suppress the verbose output of the command
sc create "vboxMyVMService" binPath= "C:\Progman Files\Oracle\VirtualBox\VBoxManage.exe startvm MyVM --type headless > NUL"
sc create "vboxMyVMService" binPath= "C:\Progman Files\Oracle\VirtualBox\VBoxManage startvm MyVM --type headless"
Still no results. All this version returned me a 1053 error. So the last call was to add the Virtualbox command to the Path
sc create "vboxMyVMService" binPath= "VBoxManage.exe startvm MyVM --type headless"
sc create "vboxMyVMService" binPath= "VBoxManage startvm MyVM --type headless"
suppressing output
sc create "vboxMyVMService" binPath= "VBoxManage.exe startvm MyVM --type headless > NUL"
sc create "vboxMyVMService" binPath= "VBoxManage startvm MyVM --type headless > NUL"
No positive result always 1053 error.
2. Assign Computer Startup Scripts
I followed this tutorial with my last hope, but no success.
What left
I'm thinking about to download the Visual Studio and try something related to create a service project.
So guys, where is my mistake? Is there hope to me?
FAQs
-
Can you switch you OS to linux?
- No. It's out of question.
-
Why you need this VM to startup at with the system?
- Unfortunately this windows 7 host is a small server for the application running over the VM. The machine it's not mine and it's the only option they gave to me to make the deploy.
-
Why you are not making the deploy of the application inside the windows host?
- I'm not running PHP, or any .NET stuff, so no.
Solution 1:
I run with NSSM.
Create a NSSM service in prompt like:
nssm/win64/nssm.exe install vbox
-
Select exec VBoxHeadless.exe like image:
Use your Windows Account in Logon (this is very important)
Install service
Works for me.
Solution 2:
I wasn't able to find a mechanism to start a VM as service with VBoxManager command without anybody required to login first.
I enabled my Ubuntu Server VM to run as service using the VBoxVmService
tool:
https://github.com/onlyfang/VBoxVmService
Brief Description: VBoxVmService is a Windows application that allows you to run Oracle's VirtualBox VMs from within a native Windows service entity.
The main reason i required this is, to start the VM without anybody required to login. Mine being a developer workstation, it get's restarted for updates, and i sometimes forget to start the VM until someone pokes me.
Here's how it works:
-
First, manually ensure the required VM starts and works fine without errors. Else will be tough to debug digging through the logs.
-
Upon installation
VMBoxService
set's it's executable as a windows service -
Edit it's configuration INI file (Refer here for full documented sample)
-
Reboot the machine or just start the
VMBoxService's
installed windows service -
Following is a sample INI
[Settings] VBOX_USER_HOME=C:\Users\YOUR_NAME_HERE\.VirtualBox PauseShutdown=8000 [Vm0] VmName=ubuntu-server ShutdownMethod=savestate AutoStart=yes
UPDATE: Supports only Win 10+