Terminal command to find out if a server is virtual or physical

command linevirtual machine

I am looking for a terminal command which doesn't require the executing user to be in the sudoers group and also to be universal and not requiring to install additional packages. So far I have found that if the system has systemd installed then I can use:

$ hostnamectl status
   Static hostname: mint
         Icon name: computer-laptop
           Chassis: laptop
        Machine ID: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
           Boot ID: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
  Operating System: Linux Mint LMDE
            Kernel: Linux 3.16.0-6-amd64

and under Icon name and Chassis I can see if it is VM or physical machine. But I was wondering if I can use lscpu, especially since it is more universal method than hostnamectl and it doesn't require systemd. My theory is that if the CPU has only one thread per core and also not listed minimum and maximum CPU frequency this should be an indication that the server is indeed virtualized.

$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    2
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 60
Model name:            Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz
Stepping:              3
CPU MHz:               2500.488
CPU max MHz:           3500.0000
CPU min MHz:           800.0000
BogoMIPS:              4988.18
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              6144K
NUMA node0 CPU(s):     0-7

I know that the if a CPU has only one thread per core doesn't necessarily means that it is VM for sure, but then all modern CPUs should have 2 threads per core and in addition I can also take into account the lack/presence of minimum and maximum CPU frequency in the lscpu output.

Best Answer

Under given conditions:

terminal command which doesn't require the executing user to be in the sudoers group and also to be universal and not requiring to install additional packages.

the obvious simplest method for unmodified VMs, which owners intentionally haven't tried to hide fact the OS is VM, is

cat /sys/class/dmi/id/product_name

More possibilities:

Outside of the given by OP author conditions there are more complicated approaches like this one: Where am I? Operating System and Virtualization Identification Without System Calls

Related Question