Solved [vbox] Is it possible for the FreeBSD guest to verify whether VirtualBox was started 'headless'?

obsigna

Profile disabled
I am running a FreeBSD systems for testing in VirtualBox. This is fully setup with a desktop environment. When I only want to work with the system on the command line, I usually start VirtualBox as --type=headless, and of course in this mode, X.org and the desktop environment would not be needed. So, I am looking for a quick check on whether VirtualBox got a head or not, for in case it is 'headless', not to start the desktop environment. Can this be done somehow?
 
As far as I understood it there's no difference from the VM's point of view. It still has a VGA adapter and the graphics are still being rendered. You just don't get a window on the host that shows it.
 
If I understand "headless" correctly, there should be nothing displayed with pciconf -l | grep vgapci ?
E.g. a computer without VGA device.
 
If I understand "headless" correctly, there should be nothing displayed with pciconf -l | grep vgapci ?
E.g. a computer without VGA device.
That would be a headless machine. VBoxManage's definition of --type headless is just to run the machine in the "headless frontend", see https://www.virtualbox.org/manual/ch08.html#vboxmanage-startvm

So, SirDice is correct, the emulated graphics adapter is still there, and you can even connect to it using RDP. From inside the VM, everything looks exactly the same.
 
Maybe it is possible to query the VirtualBox Guest Additions daemon for vm properties from inside the vm?
 
Virtualbox's definition of "headless" is more like disconnecting the monitor while leaving the graphics card in the machine. A real headless machine wouldn't have a graphics card. Although that definition is quite varied, some servers are headless too, mainly because there's no monitor or keyboard permanently attached to them. When you go to a datacenter you often find there are trolleys with a monitor and keyboard on them, so you can take that trolley to your server and hook up a monitor and keyboard locally. The server itself is then considered to be "headless".
 
If I recall correctly, in headless mode (or detachable mode) the 3D acceleration is not available through the vbox driver (mostly because there is no window to create the host OpenGL context against).

It seems like overkill but perhaps you can check for this?
I only actually know how to do this via GLX which would mean starting X11 anyway unfortunately. Perhaps EGL could be used?

I have no idea if this EGL functionality is available or if it is only NVIDIA specific: https://developer.nvidia.com/blog/egl-eye-opengl-visualization-without-x-server/

Before all this, lets check that there is definitely no sysctl from any of the vbox guest additions that provide any indication of if acceleration is available.

Finally, it is fairly cheesy but in your script to launch the VM, perhaps if it is headless, you could add something useless like a floppy disk controller and then check for that in the guest. Then if you run it via the GUI, remove the floppy disk controller and the check will then run the desktop...
 
Maybe it is possible to query the VirtualBox Guest Additions daemon for vm properties from inside the vm?
Maybe it is fully sufficient to check the virtual video cards' PCI ID.
I'd expect different ones for each vbox video mode.

Edit: Maybe check out what pciconf -lv | grep A4 vgapci shows in each of these modes.
 
Snurg No, SirDice analogy is a good one - it's like you don't have monitor connected (but you still have VGA card):

Inside headless guest:
Code:
vgapci0@pci0:0:2:0:    class=0x030000 card=0x00000000 chip=0xbeef80ee rev=0x00 hdr=0x00
    vendor     = 'InnoTek Systemberatung GmbH'
    device     = 'VirtualBox Graphics Adapter'
    class      = display
    subclass   = VGA

As host sees it: VBoxManage showvminfo tbsd01
Code:
Graphics Controller:         VBoxVGA
Monitor count:   1

I'm not aware of a way of checking how VM was started.
 
Inside headless guest:

vgapci0@pci0:0:2:0: class=0x030000 card=0x00000000 chip=0xbeef80ee rev=0x00 hdr=0x00
vendor = 'InnoTek Systemberatung GmbH'
device = 'VirtualBox Graphics Adapter'
class = display
subclass = VGA[/code]
Compare this to a non-headless configuration, for example this one from that post:
vgapci0@pci0:0:2:0: class=0x030000 card=0x040515ad chip=0xbeef80ee rev=0x00 hdr=0x00
vendor = 'InnoTek Systemberatung GmbH'
device = 'VirtualBox Graphics Adapter'
class = display
subclass = VGA

And then you know what you need to look for to answer the question "headless" or "normal".
Question solved now?

Edit:
Please be aware that the output format of pciconf has changed in FreeBSD 13.
So take this into account when scripting that check.
 
No. Although this might be a hint, you'd have to verify that. I'd rather attribute it to different versions of virtualbox, but that's just a guess of course.
I think it is rather plausible, as virtualbox mimicks the vmware adapters:
'0405' => 'VMWARE0405 SVGA II Adapter'
'0710' => 'VMWARE0710 SVGA Adapter'
with 15AD as PCI vendor ID.
But to verify, I have to install vbox and check out every and each video mode it offers.
Maybe there are even more modes that have to be taken care of.

Setting that to zero makes definitely sure that nothing will incorrectly autodetect this headless as "graphics card".
 
Thank you everybody for all the replies and ideas. As SirDice pointed already out, there are actually no differences in the enumerated graphics and other hardware from the FreeBSD guest point of view when compared normal mode with headless mode. However, all this discussion brought me the idea to switch the graphics hardware on the command line in the course of starting the VM, and then FreeBSD can see the difference:

Starting the FreeBSD VM in normal mode:
VBoxManage modifyvm FreeBSD --graphicscontroller vboxsvga && VBoxManage startvm FreeBSD

Starting the FreeBSD VM in headless mode:
VBoxManage modifyvm FreeBSD --graphicscontroller none && VBoxManage startvm FreeBSD --type headless

In the latter case, FreeBSD does not see a graphics card, and before starting gdm, I simply let the launcher check, whether the system got a graphics card or not.

Again, thank you everybody for your contributions, these helped a lot in finding a solution.
 
Back
Top