Check If A Linux System Is Physical Or Virtual Machine

por | 14 julio, 2020

Method 1 – Using Dmidecode utility

The easiest way to find if we are working on a virtual or physical machine is using dmidecode utility. Dmidecode, DMI table decoder, is used find your system’s hardware components, as well as other useful information such as serial numbers and BIOS revision.

Dmidecode comes pre-installed with most Linux distributions. Just in case, if it is not installed already, you can install it using your distribution’s package manager. Say for example, the following command will install dmidecode in DEB based systems such as Ubuntu, Linux Mint.

$ sudo apt-get install dmidecode

After installing Dmidecode, run the following command to find out whether your system is a physical or virtual machine:

$ sudo dmidecode -s system-manufacturer

If it is a physical system, you will get an output something like below.

Dell Inc.

If it is virtual system, you will get the following outputs:

innotek GmbH

For those wondering, innotek is a German-based software company that develops PC virtualization software called VirtualBox.

As you see in the above output, if it is a physical system, dmidecode will show the manufacturer’s name (i.e Dell Inc.). If it is a virtual system, then it will show the virtualization software/technology (i.e VirtualBox in our case).

Also, you can use this command to check if it is physical or virtual system.

$ sudo dmidecode | grep Product

Sample output:

[Physical system]

Product Name: 01HXXJ
Product Name: Inspiron N5050

[Virtual system]

Product Name: VirtualBox
Product Name: VirtualBox

Another command to find out if it is a physical or virtual system is:

$ sudo dmidecode -s system-product-name

Sample output:

[Physical system]

Inspiron N5050

[Virtual system]

VirtualBox

Yet another dmidecode command to find the remote system’s type is:

$ sudo dmidecode | egrep -i 'manufacturer|product'

Sample output:

[Physical system]

 Manufacturer: Intel 
 Manufacturer: Sanyo 
 Manufacturer: Not Specified
 Manufacturer: Dell Inc.
 Product Name: 01HXXJ
 Manufacturer: Dell Inc.
 Manufacturer: Dell Inc.
 Product Name: Inspiron N5050
 Manufacturer: 014F

[Virtual system]

 Manufacturer: innotek GmbH
 Product Name: VirtualBox
 Manufacturer: Oracle Corporation
 Product Name: VirtualBox
 Manufacturer: Oracle Corporation

And, one more dmidecode command is to achieve the same goal:

$ sudo dmidecode | egrep -i 'vendor'

Sample output:

[Physical system]

Vendor: Dell Inc.

[Virtual system]

Vendor: innotek GmbH

Method 2 – Using Facter utility

Facter is a command line utility to collect and display a system’s information. Unlike Dmidecode, Facter doesn’t comes pre-installed by default. You may need to install it as shown below depending upon the Linux distribution you use.

In Arch Linux, Manjaro Linux:

$ sudo pacman -S facter

In Fedora:

$ sudo dnf install facter

In CentOS, RHEL:

$ sudo yum install epel-release
$ sudo yum installl facter

In openSUSE:

$ sudo zypper install facter

Once facter installed, run the following command to check if the system is physical or virtual machine:

$ facter 2> /dev/null | grep virtual

If this command doesn’t work, try with sudo privileges:

$ sudo facter 2> /dev/null | grep virtual

Sample output:

[Physical system]

is_virtual => false
virtual => physical

[Virtual system]

is_virtual => true
virtual => kvm

Alternatively, use the following command:

$ facter virtual

Or,

$ sudo facter virtual

If it is physical machine, the output will be:

physical

If it is virtual machine, you will see output something like below.

kvm

Method 3 – Using lshw utility

The lshw utility is a small command line utility that displays the detailed hardware information of a Unix-like system. It displays all hardware details including memory configuration, firmware version, mainboard configuration, CPU version and speed, cache configuration, bus speed, etc.

Some Linux distributions comes pre-installed with lshw. If it is not installed already, you can install it as shown below.

In Arch Linux and derivatives:

$ sudo pacman -S lshw

In Fedora:

$ sudo dnf install lshw

In RHEL and derivatives such as CentOS, scientific Linux:

$ sudo yum install epel-release
$ sudo yum install lshw

In Debian, Ubuntu, Linux Mint:

$ sudo apt-get install lshw

In SUSE/openSUSE:

$ sudo zypper in lshw

After installing lshw, run the following command to find out if your system is either physical or virtual:

$ sudo lshw -class system

Sample output:

[Physical system]

sk 
 description: Portable Computer
 product: Inspiron N5050 (To be filled by O.E.M.)
 vendor: Dell Inc.
 version: Not Specified
 serial: JSQ9PR1
 width: 4294967295 bits
 capabilities: smbios-2.6 dmi-2.6 smp vsyscall32
 configuration: boot=normal chassis=portable sku=To be filled by O.E.M. uuid=44454C4C-5300-1051-8039-CAC04F505231

[Virtual system]

ubuntuserver 
 description: Computer
 product: VirtualBox
 vendor: innotek GmbH
 version: 1.2
 serial: 0
 width: 64 bits
 capabilities: smbios-2.5 dmi-2.5 vsyscall32
 configuration: family=Virtual Machine uuid=78B58916-4074-42E2-860F-7CAF39B5E6F5