Hi,
Is there a easy way to detect when my OS is running under Virtualbox?
I have this physical configuration:
Disk0: Linux OS (Ubuntu 12.10 x86_64)
Disk1: Additional Linux Data (single partition)
Disk2: Windows 7 x64
I would like to be able to boot into either Windows 7 or Linux and then run the other operating system under Virtualbox. (This currently works for running the Linux under Windows 7). I created vmdk files to access the physical disks.
I'm currently using Virtualbox 4.2 but I woudl prefer a solution all relatively recent versions (say >= 4.0).
Is there official way that I can query whether the system is currently running under Virtualbox? I want to run a script for the Linux if it is being run under Virtualbox (due to less resources) to stop redundant services and set up the network differently.
Some more details:
I do have the guest additions installed. They might attempt to run on the physical hardware as well. (Asking it for some info is ok, checking for their presence is not)
I do need a way that would be reliable with future VirtualBox versions.
It should also work on a different computer (I do not want to look at the amount of RAM, etc..).
It can be a voluntary setting in the VirtualBox configuration. (I do not care if it is possible to disable the detection)
It would be nice if it works under other virtualization software as well.
It should not rely on very specific emulated hardware being selected.
It would be nice if the method is adaptable to non-Linux guests.
It should work on both 64-bit and 32-bit guests.
I'm looking for something more elegant than "lspci|grep -i virtualbox"
Some speculation:
An interface seems to exist for mouse pointer integration and guest addition features. If that is the same for different software, detecting its presence might work? How do the guest additions interface to Virtualbox?
Detecting when running under VirtualBox from guest
Re: Detecting when running under VirtualBox from guest
I do see this device in lspci:
Might consider looking for its presence... Can I rely on finding it (in furure / past versions), and how should it be detected? (Class? Vendor + device ID? Slot? combination of those?) Would it work on any non-Virtualbox software?
A more portable method might be nice...
Code: Select all
mohag@mohagpc:~$ lspci -v -s 00:04.0
00:04.0 System peripheral: InnoTek Systemberatung GmbH VirtualBox Guest Service
Flags: bus master, fast devsel, latency 0, IRQ 5
I/O ports at d020 [size=32]
Memory at f0000000 (32-bit, non-prefetchable) [size=4M]
Memory at f0400000 (32-bit, prefetchable) [size=16K]
Kernel modules: vboxguest
A more portable method might be nice...
Re: Detecting when running under VirtualBox from guest
virt-what seem suitable for my purposes... Any idea if it uses lots of dodgy tricks, or an actual reliable method?
Does Virtualbox set the relevant CPUID bit to allow detection? (ECX bit 31)
Finding something suitable for Windows guests might be interesting...
Does Virtualbox set the relevant CPUID bit to allow detection? (ECX bit 31)
Finding something suitable for Windows guests might be interesting...