tags:

views:

341

answers:

5

In VMs OS-provided real-time scheduling tends not to be reliable. For my application I'd like to be able to detect whether I am running on a VM or not (Linux-only).

So I am looking for a nice way to detect (in C) whether I am in a virtualized environment. Depending on the VM used there seem to be various DMI and CPUID strings in use. I am primarily interested in a generic way though.

Anyone got any ideas?

A: 

Look for specific devices that only show up while you're in a VM. For instance, a display device marked "Parallels" or "VMWare" might be a good indication that you're in a VM.

Of course this only works for VMs that you know about and thus isn't very generic.

Epsilon Prime
DMI and CPUID are more useful for that kind of stuff. But those commands already suck necause they are a heuristic.
+3  A: 

facter and imvirt will both detect some virtualizations

ptman
and there seems to be at least a third tool for this: virt-whattake a look at how those project do it
ptman
And neither of those are really nice to use from C
True, that's why I added "take a look at how those project do it"
ptman
+1  A: 

I think you're going to have to do this heuristically. Part of the goal of virtualization products is to make the vm instance believe it's running on real hardware. Each virtualization product is going to simulate specific hardware, so my solution would be to make a library that you can ask "am I on a vm" and just maintain under the hood some search for evidence of vm presence. This way you still remain relatively isolated from the nitty gritty of detecting the vm.

Matt
+2  A: 

It seems that the real question you want answered is "Is real-time scheduling working unreliably?". So why not write a test that checks for that?

caf
A: 

Here is a code example: http://www.codeproject.com/KB/system/VmDetect.aspx , http://mark.michaelis.net/Blog/HowToDetectVirtualMachineExecution.aspx (but this is from year 2005)

And in some magazine I've read that virtual machine can be detected with the hardware set because VM use the limited set of emulated hardware.

StarWind Software