Hey,
This is now I got my VirtualBox VM's to reliably automatically startup and shutdown with my windows 10 host gracefully (further down I list all the ways I tried that didn't work)
1 - Get VBoxVmService - Get from here
(If you aren't familiar with github you are looking at the source files when you land on this page, to download the application you are looking for "releases" on the right hand side
2 - Install VBoxVmService
3 - Configure your VBoxVmService.ini file
I recommend savestate over acpipowerbutton but thats up to you, savestate effectively backups up the running RAM to disk, so when you restart the VM's are back where you left them when you shutdown
[Settings]
VBOX_USER_HOME="E:\VirtualBox VMs"
RunWebService=no
PauseShutdown=5000
[Vm0]
VmName=YourVm1NameHere
ShutdownMethod=savestate
AutoStart=yes
[Vm1]
VmName=YourVm2NameHere
ShutdownMethod=savestate
AutoStart=yes
4 - Edit the VBoxVmService (And this is the kicker for windows users) Edit the VBoxVmService to start with the user account and password that you will login with when you want to manage your host.
If you leave it running as local system, then when you log on to windows and open the "Oracle VM VirtualBox" application to check on or edit the vm's they will appear as stopped (even though they are in fact running and fine).
Additionally the virtual machines started by the VBoxVmService will not appear to be using/consuming RAM or CPU so you get inaccurate information through task manager performance.
This is because by default a user doesn't see services or processes started by local system.
That is it really, my VM's now reliably start and stop with the host as you would expect!
Here is some details around what Host/vm setup I am running
My VirtualBox "Server"/Host
CPU: AMD 3400G
RAM: 32Gb Ram DDR4
DISK1: Boot - 240Gb SATA SSD
DISK2: Data/VMs - 1Tb NVMe SSD
DISK3: Backups - 4tb SATA
OS: Windows 10 Pro
VirtualBox Virtual Machine 1 (VM1)
CPU: 4 core
RAM: 8Gb
Disk1: Boot - 200Gb (Dynamic)
OS: Windows Server 2019 Standard
Role: AD/DNS/DHCP
VirtualBox Virtual Machine 2 (VM2)
CPU: 4 core
RAM: 8Gb
Disk1: Boot - 200Gb (Dynamic)
Disk2: Data - 500Gb (Dynamic)
OS: Windows Server 2019 Standard
Role: Applications/RDS
Stop here, the information below relates to all the other ways I tired to get it working first, I DID NOT get my VirtualBox VM's to reliably automatically startup and shutdown with my host gracefully (read the post above for what have now got working smoothly. I would consistently get the error when you logged on to windows that the last shutdown was unexpected.
I got these answer from several different forums posts across the internet and though centralising them would be helpful.
I have left this here to help people using search engines show up on this page.
Surely there are quite a few people out there trying to achieve the same thing!
1 - Make sure your virtual machines startup and shutdown fine in headless mode using the GUI first
2 - Configure the VM's to force shutdown when they receive the ACPI shutdown command
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" setextradata "VM1" GUI/DefaultCloseAction Shutdown
(Run this for each VM as required, changing VM1 for the name of the VM)
3 - Create the startup script
C:\Scripts\StartVMs.bat
REM -----------------------------------------------------------------------------
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm VM1 --type headless
timeout 10
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" startvm VM2 --type headless
REM -----------------------------------------------------------------------------
4 - Create the shutdown script
C:\Scripts\StopVMs.bat
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "ITP-HOB-VM-01" acpipowerbutton
"C:\Program Files\Oracle\VirtualBox\VBoxManage.exe" controlvm "ITP-HOB-VM-02" acpipowerbutton
timeout 30
5 - Use Task Scheduler to run the script at startup
- Open Task Scheduler
- Create basic task
- Name: Start VM's
- Choose the trigger as "When the computer starts"
- Action is start a program, choose C:\Scripts\StartVMs.bat
This will create the scheduled task
- Edit the properties of the task and under the general tab select "Run whether a user is logged or not" (This will make you enter the password when you save the scheduled task)
6a - Use Task Scheduler to run the script at shutdown
- Open Task Scheduler
- Create basic task
- Name: Stop VM's
- Choose when a specific event is logged
- Log: System
- Source: User32
- EventID: 1074
- Action is start a program, choose C:\Scripts\StopVMs.bat
This will create the scheduled task
- Edit the properties of the task and under the general tab select "Run whether a user is logged or not" (This will make you enter the password when you save the scheduled task)
6b - Use Gpedit to run the script as a shutdown script
Comments