7

Oracle VirtualBox on Windows

Hi All,

Is there a way to start a vm headless (vboxheadless -s ) but one can close that command window or if I add that as a startup item will that make it run silent ?

I have successfully exported a appliance (linux vm), when I will do the batch import will it retain the settings I had configured originally or will one would have to assign bridged adapter, amount of ram, etc ?

will be grateful for your suggestions ! Kind Regards

EDIT : Iain, if one wants to script the GuestAdditions install on first boot in a CentOS VM, shall I just put the commands ./VBOXLinux-x86-additions.run to the bash script and it will run at startup, any thoughts on this would be really helpful.

Kind Regards

Mutahir
  • 2,347
  • 2
  • 32
  • 42
  • Does the export also take care of hardware configurations? I thought there was post-changes that had to be done sometimes, but maybe I'm out of date with doing that. Or all I did was convert a drive format so they could be mounted in a different VM system, not actually run the OS from there. – Bart Silverstrim Oct 06 '10 at 12:47
  • There is some info [here](http://www.virtuatopia.com/index.php/Understanding_and_Installing_VirtualBox_Guest_Additions) on scripting the GA install. I've never tried it though. – user9517 Oct 17 '10 at 21:45

5 Answers5

4

If you use

vboxmanage import ovffile.ovf --dry-run

you will get a report telling you what configuration is going to be applied when the import is actually done. You'll also get advice on how to make changes if required.

As to running vboxheadless detached from a command line and a window it's not as straightforward as you may think. A simple

start /b vboxheadless -s vmname

appears to work in that it detaches from the command line but if you close the window the child process dies too and the 'power cord' is pulled from your vm.

To solve this use a small vbs script test.vbs

Set WshShell = WScript.CreateObject("WScript.Shell")
obj = WshShell.Run("c:\temp\test.bat", 0)
set WshShell = Nothing

My test.bat

@echo off
vboxheadless -s vmname
user9517
  • 114,104
  • 20
  • 206
  • 289
  • Hi Iain, Thanks again for your assistance, so basically : a) I will copy paste the vb script and save it as say "vmheadless.vbs" b) create / copy the bat file and save it in c:\temp\test.bat c) then when I execute the vb script it will start the vm with no window attached to it ? I will ofcourse edit the bat file and vmname appropriately Kind Regards – Mutahir Oct 07 '10 at 15:06
  • 1
    Yes, that's how to use it. You can change the name of the batch file, just edit the vbscript accordingly. – user9517 Oct 07 '10 at 15:46
  • Hi Iain, thank you so much for your prompt responses and suggestions. I have just realized another point which might be an issue : When all automation of this process is done, say 10 people import this via windows batch on there machine : a) Will the SSH Keys I have generated on these client VMs and have added rsa.pub to the main db server (so no passwd required while scp download) so they (VMs) can download DB off our local db box (linux too) or will they remain the same on it ? Security isn't a concern here as everything is locked and this is pure internal. Thanks and Regards – Mutahir Oct 08 '10 at 09:02
  • 1
    The keys will all be the same and so (in your environment) should work as you want. – user9517 Oct 08 '10 at 09:29
  • Hi Iain, I just tested the script procedure you mentioned to start headless vms without a cmd window and when I execute the VBS file (same as yours) nothing happens, the batch test.bat and headless.vbs are in the same directory. I have also given the full path of virtualbox c:\programfiles\oracle\virtualbox in quotes too. – Mutahir Oct 08 '10 at 10:25
  • Hi Iain, It worked :-) on Windows 7 command prompt I had to type : Browse to the path of scripts location To execute the script I had to type Wscript headlessvm.vbs and it worked without leaving the command window open, I closed the window and I am ssh'd into the linux vm :-) WoW :-) Thanks for your support - Will ask some more questions as and when they arise :-) Kind Regards – Mutahir Oct 08 '10 at 10:55
  • Hi Lain, would you know, how would one shutdown the centos linux vm in virtualbox via windows command line, I tried using vboxmanage controlvm but can't seem to find a way to shutdown properly, or shall i create another linux script with
     shutdown -h now
    , or shall I use
    vboxmanage guestcontrol execute /root/scripts/shutdownscript.sh 
    - Thanks
    – Mutahir Oct 14 '10 at 11:38
  • 1
    If your system will shut down cleanly when sent the acpipowerbutton event is sent try `vboxmanage controlvm VMName acpipowerbutton` – user9517 Oct 14 '10 at 12:04
  • Thanks Iain, so basically for centos vm, I will create a windows batch which would have `vboxmanage controlvm centosvm acpipowerbuttom` and as soon as that is executed, it will send the shutdown signal inside the linux box. - cool thanks :-) How do you highlight the code and commands in comments / posts on SF ? I have checked the formatting help and did two spaces before the code but no luck :-) (Sorry about being off-topic). – Mutahir Oct 14 '10 at 13:49
  • 1
    `\`backtics are your friend\`` – user9517 Oct 14 '10 at 13:57
  • `ERROR: The machine 'VMCentOS' does not have an open session` Hi Iain, I have a script saved in `/root/test.sh` (with x permission on it) I then type the following `VMCentOS` is the VM Name : `VBoxManage --nologo guestcontrol execute "VMCentOS" "/root/test.sh" --username root --password oxford --verbose --wait-for stdout` Getting the error above (right on top of this comment), I am using your instructions to run this vm headless and it is switched on, I am SSH'd into it with root. Will be grateful as always for your insight onto this. Kind Regards – Mutahir Oct 14 '10 at 15:29
  • 1
    I can only force that error message buy trying to talk to the machine when it's powered off - are you sure the machine is running ? – user9517 Oct 14 '10 at 19:09
  • Hi Iain, I had forgotten to install `Guest Additions` in CentOS, once installed I was able to shut down the vm gracefully via `vboxmanage controlvm centosvm acpipowerbutton` - That is all good. I am now trying to run a bash script inside the VM via `vboxmanage guestcontrol execute "/path/to/script/" --username root --password rootpasswd` Will post my feedback on that too, but if you have any thoughts on it you can always enlighten as you have been :-) Thanks so Much !!! – Mutahir Oct 15 '10 at 09:24
  • This works for me `VboxManage guestcontrol execute "OpenSolaris" "/export/home/user/test.sh" --username user --password password --wait-for stdout` – user9517 Oct 15 '10 at 09:35
  • Hi Iain, can you please check another question of mine - when you get time ? `http://serverfault.com/questions/195298/virtualbox-import-same-mac-address` – Mutahir Oct 27 '10 at 12:01
  • Just follow @Karl's answer. Simpler, faster. – kyb Oct 22 '17 at 19:54
3

This is pretty old post but I spent a lot of time looking for this

Here's what I use

VBoxManage.exe startvm "myvm" --type "headless"

And to stop it

VBoxManage.exe controlvm "myvm" savestate 

or poweroff

I have put these in the Widows 7 task scheduler so it starts and stops with Windows.

Start:
Trigger at start up

Shut down:
Trigger on an Event

System event:
Source User32
Event ID 1074

The one issue I have found with this is if the IP changes it becomes difficult to figure out the right IP address.

kyb
  • 115
  • 6
Karl
  • 31
  • 1
  • Nice. But on Win10 trigger 'at startup' does not work for me, only 'at log on' works. – kyb Oct 23 '17 at 11:15
  • @Karl Which user account are you using to run these tasks in the scheduler? Is `Run whether user is logged on or not` selected? (Or `Run only when user is logged on`?) The former requires running `VBoxHeadless` non-interactively, and `VBoxManage.exe` is not able to find it during shutdown. – Davor Josipovic Aug 11 '19 at 22:07
0

AFAIK when you import the applicance it will hold the settings you had on the machine you exported it from.

See if this post on the VirtualBox forum can help you.

tombull89
  • 2,958
  • 8
  • 39
  • 52
0

I am using a small opensource application named VBoxVmService, which is very helpful in this type of scenario. It enables you to run your VirtualBox VMs in headless mode as windows services (one service for each VM). It is hosted on Sourceforge at:

http://vboxvmservice.sourceforge.net/

You can configure the VMs to start as service in a simple ini file. Documentation is provided with the download.

Be aware of the fact that the started VMs do not show up in the VirtualBox GUI application as started (differing from Linux, where those can be seen). If you should need to reconfigure your VMs, you will need to shutdown the service first (the supplied tray miniapp of VBoxVmService is very helpful there), then make the change in the VirtualBox GUI and then lauch the VM service again.

I added this proposal, because it may be more convenient to some users...

Peter Brennan
  • 591
  • 5
  • 12
0

This works well for me

VBoxManage startvm --type headless "Name of guest to start"
roaima
  • 1,567
  • 13
  • 26