📜 ⬆️ ⬇️

Linux to server with Windows Server, or Vbox \ VmWare as a service



Start


I was faced with the task of running when the computer boots (as a service), virtual machines on Windows Server 2008R2, but bypassing the problems of Hyper-V.
These tips are suitable for non-server systems too.
Searches were conducted on the Internet, and the results turned out to be quite a lot, but the real work, as it always happens - only one.
The torments were long, but they were crowned with success, which I would like to write about.

Stage one, erroneous, but interesting.


The first thing that was found - vboxctrl, for VirtualBox.
This utility is interesting and functional, but with different settings and tests it did not start the machine.

Description and the official development site is here .
')
For those who want to try to configure any option I want to warn you - the name of the machine must be strictly merged, in Latin characters, without special characters, otherwise the utility will not see it. As well as the path to the folder should not contain characters of the locale language (not related to Latin).

My options (Windows 2008 R2)
Options:
vboxctrl64.ini
[VBoxCtrl]
VboxInstallPath D: \ Program Files \ Oracle \ VirtualBox \
VboxUserHome C: \ Users \ {Your name} \ .VirtualBox
VmName ABC
ShutdownCommand savestate
ServiceName DEB1
Loglevel 1
Priority Normal

If you have no desire, becomes the man who laid down the server, then do not put Idle and Below Normal, even with the machine turned off, as an application, it terribly overloads the computer.

Options:
vboxctrltray.ini
[global]
UpdateCheck = 1
[DEB1]
ConfigFile = D: \ Program Files \ Oracle \ VirtualBox \ vboxctrl.ini


For service:
(The easiest way is to create two shortcuts and set add-delete parameters)
Run as Administrator!
To install the service run:
vboxctrl64 -i

To remove a service, run:
vboxctrl64 -u


also in
% SYSTEMROOT% \ system32 \ config \ systemprofile
need to copy
.VirtualBox
from user folder
C: \ Users \ {Your name} \
necessarily, because he sees the configuration from the user's folder, but does not use it, but uses only the system one (what the problem is, I did not understand).

Wrong stage for vmvare I omit, because he is really wrong, his performance is zero.

Stage Two, correct, workable, VirtualBox


To install the service, the old thing is used - two files from the Windows Resource Kit to create a user process that will start our machine.

The files Srvany.exe and Instsrv.exe, which are included in the Windows Resource Kit, I took from here. Both files need to be placed in C: \ Windows \ system32

(DEB1 is an example, the name of the car that I had.)
Next, we need to start the console (start> cmd (as administrator)) and add an entry to it, replacing the bold font with the name of the future service, the first name should be without a space, the second one, which one will like:
sc create DEB1 binPath = "% SystemRoot% \ System32 \ srvany.exe" start = auto DisplayName = " VB VM Debian "

If everything went well, then it will be written "successfully."
To make sure that the process has been created, you need to start services.msc, or just look at the “Services” tab.

Next you need to add parameters to the registry, create a file
Ways and machine name to set those in your system.
DEB1.reg
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ DEB1 \ Parameters]
"Application" = "\" D: \\ Program Files \\ Oracle \\ VirtualBox \\ VBoxHeadless.exe \ ""
“AppParameters” = "\" - s DEB1 -vrdp = off \ ""
"AppDirectory" = "\" D: \\ Program Files \\ Oracle \\ VirtualBox \\ \ ""

Further, if you want the state of the machine to be preserved when the computer is shut down, then we run gpedit.msc and find Computer Configuration / Windows Settings / Scripts / Shutdown (Computer Configuration \ Windows Configuration \ Scripts (Start \ End) \ End \).
Create a script and call it.
D: \ Program Files \ Oracle \ VirtualBox \ VBoxManage.exe
or select the path to it with the browse button, set the parameters
vboxmanage controlvm deb1 savestate
DEB1 must be replaced with the name of your car.
Copy the .VirtualBox folder from C: \ Users \ {Your name} \ (where {Your name} is your account name) to C: \ Windows \ System32 \ config \ systemprofile \ This needs to be repeated after each change of the machine properties, otherwise it may not start, or it will start with incorrect (irrelevant) changes the next time.
You can check whether the machine is started by searching the VBoxHeadless.exe process, if it is, then the machine is running.

Stage Three, VMware Player, as a service



New versions of VMware virtual machines allow you to automatically scale the RAM memory of the virtual machine taking into account the available physical memory, for this you only need to add a few parameters to the Vmx file.
memsize = "2048"
MemAllowAutoScaleDown = "TRUE"

In this case, the virtual machine will dispose of 2 GB of RAM, if any.
On machines with less than 2 GB of RAM, the player will automatically adjust the amount of used, taking into account the available RAM.
Memsize 2048 is not the limit.
If you have more than 2 GB of memory installed, you can simply increase this number.

On the machine on which the service will run, install VMware Player .
Creating a service for VMWare Player is similar to VirtalBox.
You will need two files: instsrv.exe and Srvany.exe, from the Windows 2003 Resource Kit . Both files need to be placed in C: \ Windows \ system32 \

Add fields to the Vmx file so that VMware Player suppressed all “Ok” messages generated by the user interface and did not show the user the interface.
DEB1r.vmx
……
hints.hideAll = "TRUE"
msg.noOk = "TRUE"
...


Create the VirtualServer service on the target machine using instsrv.exe.
instsrv VirtualServer "% SYSTEMROOT% \ System32 \ srvany.exe"
Add registry keys for Srvany.exe so that it runs vmplayer.exe with your virtual machine.
DEB1.reg

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ DEB1 \ Parameters]
"Application" = "\" C: \\ Program Files \\ VMware \\ VMware Player \\ vmplayer.exe \ ""
"AppParameters" = "\" C: \\ VM \\ DEB1.vmx \ ""
"AppDirectory" = "\" C: \\ VM \\\ ""

To use another Vmware product, such as ACE, change the value of the “Application” key. To use another virtual machine, change the value of “AppParameters”.

Create a virtual machine startup file called start-vm.bat. This script first checks if the virtual machine files are installed and that the service is not running. It then kills all old VMware processes and eliminates various state files since the last virtual machine startup. At the end, the virtual machine service starts.
:: :: start-vm.bat :: :: If the service is already running, then skip starting it net start | grep -q -i "DEB1" if %ERRORLEVEL% == 0 goto noServer :: To make sure that lingering processes are dead, force kill the process taskkill /F /IM vmplayer.exe taskkill /F /IM vmware-vmx.exe :: Remove *.lck, *.vmss from the grid directory del "C:\VM\*.lck" del "C:VM\*.vmss" del "C:\VM\*.vmem" :: Start the server service net start DEB1 :noServer 


Create a batch file to stop the virtual machine called stop-vm.bat. The virtual service stop script kills any VMware processes associated with the running virtual machine.
 :: :: stop-vm.bat :: :: Stop the service net stop DEB1 :: Force kill the processes taskkill /F /IM vmplayer.exe taskkill /F /IM vmware-vmx.exe :noServer 


Destroying the virtual machine process is the same as if you unplugged the power cord on a physical computer. If the state of the virtual machine does not matter, then you can use the nonpersistent disk function. Since the disk contents do not change while the virtual machine is running, this termination of the process will not affect the state of the virtual disk.

To start virtual machines when Windows starts, you need to place the startup script in% SYSTEMROOT% \ System32 \ GroupPolicy \ Machine \ Scripts \ Startup. For this example, the startup script is the start-vm.bat file.
On the computer, you need to make start-vm.bat start at system startup, adding it to the list of auto startup group policies. This can be done with gpedit.msc, the group policy editor. In the Computer Configuration / Windows Settings / Scripts / Startup Properties section, and open the Group Policy editor \ Scripts (Start \ End) \ Start \) group policy editor. Click the Add button and enter the name of the virtual machine startup script, similar to the previous one.

Do the same for the group policy Shutdown (Shutdown), but use stop-vm.bat as a shutdown script. Adding a group policy Shutdown (Shutdown) is not strictly required, but it may be important to start stop-vm.bat if it contains more commands than just completing the virtual machine process.

Total


In my personal experience, the option with VirtualBox turned out to be simpler, but if you need to run BSD systems, you will still need VmWare, it works much more stable with them, but Linux works better under VirtualBox.

Source: https://habr.com/ru/post/160553/


All Articles