How can a program detect that Ubuntu is running as a virtual machine?
I am trying to run a program via Ubuntu 16.04 as a Virtualbox VM.
The binary of this program checks if it's running on a virtual machine, and does something different on a VM than if it is on a given computer.
How can I know what the binary is querying? Can I use something like strace
or ldd
for this?
I would like to be able to run the binary as if it was on a real machine, not a VM. I presume there must be a way to change what's reported by the Ubuntu 16.04 when the binary queries it.
Solution 1:
People and apps have started to code dmidecode parsing, special instruction handling (vmware) and other things. But often such code gets outdated no more matching new versions and virtualization technologies.
IMHO by far the most reliable way is to rely on the nowadays ubiquitous systemd and just call systemd-detect-virt
The benefits are clear, many VM and container types are already implemented, you get updates along new systemd versions and have less own code that you have to maintain.