How To Check If A Linux System Is Physical Or Virtual Machine

How To Check If A Linux System Is Physical Or Virtual Machine

Most of the time, you will be accessing and managing your servers remotely. You will not always have physical access of your servers, and you may not actually know where is your server located. However, it is possible to check if your Linux system is physical or virtual using couple of Linux utilities, no matter where it is located. This guide explains how to check whether the Linux system you’re working on is a physical server or a virtual server.

Check If A Linux System Is Physical Or Virtual Machine

There can be many ways to find if a system is physical or virtual. The following are the only methods that I am aware of right now. I will update if I find any other ways in the days to come.

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

As you may know, 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 (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 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:

sudo facter 2> /dev/null | grep virtual

Sample output:

[Physical system]

is_virtual => false
virtual => physical

[Virtual system]

is_virtual => true
virtual => kvm

Or, just use the following command:

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, 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

Method 4 – Using dmesg utility

We can find the system’s type using dmesg utility. dmesg is used to examine or control the kernel ring buffer.

To check if your Linux system is physical or virtual, simply run:

sudo dmesg | grep "Hypervisor detected"

If your system is physical, you will not see any output.

If your system is virtual machine, then you will see an output something like below.

[ 0.000000] Hypervisor detected: KVM

Method 5 – Using hostnamectl command

We can find if out system is either virtual or physical using hostnamectl command. It requires systemd to work.

hostnamectl status

Or,

hostnamectl

Sample output:

[Physical system]

Static hostname: sk
 Icon name: computer-laptop
 Chassis: laptop
 Machine ID: 84e3c8e37e114ac9bc9f69689b49cfaa
 Boot ID: 19cf3572e1634e778b5d494d9c1af6e9
 Operating System: Arch Linux
 Kernel: Linux 4.10.13-1-ARCH
 Architecture: x86-64

[Virtual system]

Static hostname: ubuntuserver
 Icon name: computer-vm
 Chassis: vm
 Machine ID: 2befe86cf8887ba098b509e457554beb
 Boot ID: 8021c02d65dc46a1885afb25dddcf18c
 Virtualization: oracle
 Operating System: Ubuntu 16.04.1 LTS
 Kernel: Linux 4.4.0-78-generic
 Architecture: x86-64

Method 6 – Using systemd-detect-virt

systemd-detect-virt detects the virtualization technology and can distinguish full machine virtualization from hardware or container virtualization.

Run the following command to check if the system is physical or virtual:

systemd-detect-virt

Sample output:

[Physical machine]

none

[Virtual machine]

oracle

Method 7 – Using virt-what script

The virt-what is a small shell script developed at Red Hat to find if we are running in a virtual machine or physical machine. virt-what is packaged for all popular Linux distributions, such as RHEL, Fedora, CentOS, Debian, Ubuntu, Arch Linux (AUR).

In Arch Linux, you can install it from AUR using yaourt or packer helpers.

yaourt -S virt-what

Or,

packer -S virt-what

In RHEL, Fedora, CentOS:

sudo yum install virt-what

On Debian, Ubuntu:

sudo apt-get install virt-what

Once installed, run the following command to display to find if your system is either physical or virtual:

sudo virt-what

If nothing is printed and the script exits with code 0 (no error), then it can means that either system is physical or a type of virtual machine which we don’t know about or cannot detect.

If your system is Virtual, you will see an output like below.

virtualbox
kvm

For more details, refer the project’s homepage.

Method 8 – Using imvirt script

The imvirt is yet another little perl script that helps you to detect if we’re running on a virtual machine.

In Arch Linux, you can install it from AUR using yaourt or packer helpers.

yaourt -S imvirt

Or,

packer -S imvirt

On Debian, Ubuntu, Linux Mint:

sudo apt-get install imvirt

Once installed, run the following command to display to find if your system is either physical or virtual:

sudo imvirt

If your system is physical, the output would be:

Physical

if the system is virtual, you will see:

KVM

And, that’s all for now. Do you know any other ways to find whether the Linux box is physical or virtual? Feel free to let me know in the comment section. I will be soon here with another useful guide. Until then stay tuned with Linux Masters Wiki.

Cheers!

 
Enjoyed this video?
How To Check If A Linux System Is Physical Or Virtual Machine
"No Thanks. Please Close This Box!"