bdutta74
bdutta74

Reputation: 2860

Detect execution within Virtual-Machine, in Linux?

Need a Linux application to detect if it is executing in a Virtual-Machine (s.a. VMware ESX/ESXi, Xen, Oracle Virtualbox, Microsoft Virtual server etc.) Based on the outcome of this detection, some software licensing rules need to be enforced.

I am aware that there are some commercial software libraries/frameworks meant for licensing, that can perform such detection, but we need to roll our own due to several reasons.

What are some of the ways and means to achieve such detection ?

Upvotes: 0

Views: 616

Answers (2)

Existentialist
Existentialist

Reputation: 332

Old answer, but I've made a VM detection library in C++ that is meant to do exactly this.

https://github.com/kernelwernel/VMAware

All the techniques mentioned in this post are included in the library.

Upvotes: 1

user2234712
user2234712

Reputation: 89

For modern hardware-accelerated (VT-x) hypervisors (VMware, VirtualBox, KVM/QEmu), they all set the "hypervisor" CPUID bit, which is quite simple to read from Linux. Open the file /proc/cpuinfo, and look for "hypervisor" in the flags line.

It's not 100% though. Software based hypervisors (Bochs, etc) will not set it, and the bit is not enforced, so one could modify QEmu to not set the bit for instance. But, it might be enough for your uses.

Upvotes: 1

Related Questions