Virtualbox Start VM Headless on Windows

Tagged:

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




rihatumH
2010-10-06 12:16:03 Scores:2
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 SilverstrimH
2010-10-06 12:47:18 Scores:0
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.
IainH
2010-10-17 21:45:31 Scores:0

2 answers

Answer 1
Scores:1

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
Iain H
2010-10-06 20:51:06
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
rihatum H
2010-10-07 15:06:05 Scores:0
Yes, that's how to use it. You can change the name of the batch file, just edit the vbscript accordingly.
Iain H
2010-10-07 15:46:54 Scores:1
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
rihatum H
2010-10-08 09:02:21 Scores:0
The keys will all be the same and so (in your environment) should work as you want.
Iain H
2010-10-08 09:29:46 Scores:1
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.
rihatum H
2010-10-08 10:25:38 Scores:0
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
rihatum H
2010-10-08 10:55:06 Scores:0
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
rihatum H
2010-10-14 11:38:33 Scores:0
If your system will shut down cleanly when sent the acpipowerbutton event is sent try `vboxmanage controlvm VMName acpipowerbutton`
Iain H
2010-10-14 12:04:03 Scores:1
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).
rihatum H
2010-10-14 13:49:34 Scores:0
`\`backtics are your friend\``
Iain H
2010-10-14 13:57:18 Scores:1
`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
rihatum H
2010-10-14 15:29:10 Scores:0
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 ?
Iain H
2010-10-14 19:09:06 Scores:1
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 !!!
rihatum H
2010-10-15 09:24:51 Scores:0
This works for me `VboxManage guestcontrol execute "OpenSolaris" "/export/home/user/test.sh" --username user --password password --wait-for stdout`
Iain H
2010-10-15 09:35:11 Scores:0
Hi Iain, can you please check another question of mine - when you get time ? `http://serverfault.com/questions/195298/virtualbox-import-same-mac-address`
rihatum H
2010-10-27 12:01:59 Scores:0
Answer 2
Scores: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 H
2010-10-06 12:44:53
Share |
View original post at serverfault.com

Related topics

Run a Virtual Machine from Virtualbox without launching virtualbox.

since you're able to close the Virtualbox window after booting the virtualmachine, I was wondering: Is there a way (command or shortcut) to run a VM installed in Virtualbox without having to open and go through Virtualbox's main window in the process? I know that the VM is still running ...

Windows: Creating a service out of headless application (VirtualBox). Stop/shutdown script?

My client needs to have a virtualized Linux running on his Windows Server 2008 (R1). I've managed to setup VirtualBox as a service with srvany, but I see no way of creating a kind of 'stop script' so the virtual machine powers off correctly when I stop the registered service. I ...

Fusion: create "headless" virtual machines?

Is there a way to run a VM in Fusion that starts when the machine does, but I can then access via Remote Desktop (Windows) or ssh (Linux) rather than by opening the Fusion app, starting the VM, and then connecting however I'd prefer (rdp/ssh)? I know this is possible with ...

How to start a service with certain start parameters on Windows

How do I start a service with certain parameters? In another question I have found net start servicename blah but if I try this, net throws a syntax error at me. What am I doing wrong? Edit: To clarify net start servicename works just fine, but I need to pass ...

Windows hangs during headless build

We are trying to automate a build of one of our products which includes a step where it packages some things with WISE. At one point WISE pops up a window with a progress bar on it to show how it is doing. If one is connected to ...

How to select OS via grub on headless system ?

I have a dual boot system (Linux and Windows) that I normally run headless and which boots by default into Linux (which is what I use mainly). This all works fine, except that on occasions when I want to boot Windows I have to plug in a keyboard and monitor ...

how do i create a 1 line command using "sc start" or "net start" on services whose names match a pattern?

I am creating a batch file to start several services, instead of enumerating each "net start" with the exact service name, how can i create the script to run "net start" on any service that begins with "EED" Thanks. ...

How do I make VirtualBox start when Ubuntu Server starts?

I have VirtualBox and I want to install MS Windows in it. How can I make VirtualBox start when Ubuntu Server does, so that I don't need to manually start Windows? ...

virtualbox ose windows binaries

Hello Sun's virtualbox windows binaries are under 'non-commercial' license so can't be used in any company. But source code is GPL. Is it any resource on the network that has a virtualbox compiled binaries for windows? Added a bounty to see if I can get a little more feedback. ...

[C#,.Net,Windows] Does start the same thread possible? (Thread create=>Thread Start=>Thread Finish computation=>Start the same thread with other data again))

Hi, everybody I have a some computation program. Now, this program is a single-thread, I need to enhance it to do it multi-thread. In general, program computes, dynamic evolution of thermal circuit (Some configured types of different involved elements (Tube, Pump, Active zone, and its connection), for each of it for ...