VMware Linux Server -- how can you tell if you are a vm or real hardware?

Solution 1:

Use standard Linux tools to inspect the hardware on the system.

cat /proc/scsi/scsi

or

ethtool -i eth0

or

dmidecode | grep -i vmware

If the output of these commands shows hardware with a manufacturer name of "VMWare", you're on a VMWare VM. Multiple commands are provided here because system configurations and tools differ.

Solution 2:

facter virtual 
xenu

indicates that it’s a VM. If it returned “physical” then the opposite is true (not a VM), eg:

facter virtual
Physical

Solution 3:

You might be able to get and idea by looking around under /sys. For example /sys/class/dmi/id/sys_vendor has a value of VMware, Inc..

If it is installed you can use lshw. The command lshw -class system returns this on my system:

server1
    description: Computer
    product: VMware Virtual Platform
    vendor: VMware, Inc.
    version: None
    serial: VMware-...
    width: 64 bits
    capabilities: smbios-2.4 dmi-2.4 vsyscall64 vsyscall32

Solution 4:

There is a handy app that might help called virt-what. I haven't used it with VMWare, but it did work nicely with Qemu.


Solution 5:

Some virtual environments name some of their virtual devices with names that are a bit tell-tale, for example, VirtualBox presenting a graphics card that calls itself "VirtualBox Display Adapter". But looking for those ties you to a particular VM and possibly a narrow range of versions.

It might be possible for your code to see what sort of virtualisation it could set up. If that fails entirely, you might be in a VM. But you just as might easily be on a box that doesn't have any VM capable hardware.