Table of Contents
In this example, I will take you through 13 Easy methods to check if a Server is a Physical or Virtual in Linux or Unix. If you are working on Unix/Linux Based Systems then you might have faced a situation where you needed to find if a particular Server is a Physical or Virtual Server. This information required for various use cases like if someone asked to check the Server Serial number then it won’t be available if the Server is Virtual hence it is very important to first find if the Server is physical or virtual.
There are various Virtualization technologies available like Xen Virtualization, VMware, Hypervisor, KVM, Virtualbox etc. An Organization might be using any of them so it is very much obvious that you need to be aware of all the possible tools which can be used to find if a Server is Physical or Virtual. I have explained all the possible tools that can be used in various Linux or Unix platforms to verify if the Server is physical or virtual. If you Know about any more tool apart from this then please let me know in the Comment Box.
Check If a Unix/Linux Server is Physical or Virtual
Also Read: 5 Easy Examples to Delete Files and Directories Owned by Specific User and Group in Linux
Method 1: How to Check If a Unix/Linux Server is Physical or Virtual using dmesg output
If you want to check that your Unix/Linux server is physical or virtual using dmesg
command then you need to simply grep the virtual keyword from dmesg
output as shown below. If it is a virtual server then you will see output like below and if it is a Physical machine then you won’t see anything on the output.
[root@localhost ~]# dmesg | grep -i virtual [ 0.000000] DMI: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006 [ 0.000000] CPU MTRRs all blank - virtualized system. [ 0.000000] Booting paravirtualized kernel on KVM [ 0.384527] KVM setup paravirtual spinlock [ 0.953942] systemd[1]: Detected virtualization kvm. [ 1.005975] systemd[1]: Starting Setup Virtual Console...
NOTE:
root
user to run all the below commands.You can use any user with sudo
access to run all these commands. For more information Please check Step by Step: How to Add User to Sudoers to provide sudo
access to the User.Method 2: How to Check If a Linux Server is Physical or Virtual using dmidecode command
If you want to check your Unix/Linux System is Physical or Virtual using dmidecode
command then you need to grep the Line starting with System Information
and 3 lines after that as shown below. If it is a Virtual machine then you will see that information in the Product Name
as shown in the below output.
[root@localhost ~]# dmidecode | grep -A3 '^System Information' System Information Manufacturer: innotek GmbH Product Name: VirtualBox Version: 1.2
If you do not have this tool installed in your RHEL/CentOS
based Servers then you can install it by simply using yum install dmidecode -y
command as shown below.
[root@localhost ~]# yum install dmidecode -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.mirrors.estointernet.in * epel: mirror.telkomuniversity.ac.id * extras: centos.mirrors.estointernet.in * updates: centos.mirrors.estointernet.in Resolving Dependencies --> Running transaction check ---> Package dmidecode.x86_64 1:3.2-3.el7 will be installed --> Finished Dependency Resolution
If you do not have this tool installed in your Ubuntu/Debian
based Servers then you can install it by simply using apt install dmidecode
command as shown below.
root@localhost:~# apt install dmidecode Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: linux-headers-5.3.0-26 Use 'apt autoremove' to remove it. The following NEW packages will be installed: dmidecode 0 upgraded, 1 newly installed, 0 to remove and 150 not upgraded. Need to get 50.9 kB of archives. After this operation, 183 kB of additional disk space will be used.
Method 3: How to Check If a Linux Server is Physical or Virtual using lscpu command
You can use another useful command called lscpu
(List CPUs) to check if your Linux Server is Physical or Virtual. Here if you check the Hypervisor vendor and Virtualization type then you will come to know if this Server is physical or virtual.
[root@localhost ~]# lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 1 On-line CPU(s) list: 0 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 78 Model name: Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz Stepping: 3 CPU MHz: 2592.000 BogoMIPS: 5184.00 Hypervisor vendor: KVM Virtualization type: full L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 4096K NUMA node0 CPU(s): 0 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc eagerfpu pni pclmulqdq monitor ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch invpcid_single fsgsbase avx2 invpcid rdseed clflushopt md_clear flush_l1d
lscpu
is the part of util-linux
package so most probably it will be available in your Linux Server by default. You don’t have to install it manually.
For RHEL/CentOS Servers:-
[root@localhost ~]# rpm -qf $(which lscpu) util-linux-2.23.2-63.el7.x86_64
For Ubuntu/Debian Servers:-
root@localhost:~# dpkg -S $(which lscpu) util-linux: /usr/bin/lscpu
Method 4: How to Check If a Linux Server is Physical or Virtual using lshw command
lshw
is commonly known as List Hardware. This command will show all the installed hardware in your System. If you only check the first 10 lines of output using head
command then you will be able to see the product information as shown below.
[root@localhost ~]# lshw | head localhost 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=F1C1E834-65FA-4DD2-B7E3-D295527D29A5 *-core
If you do not have this tool installed in your RHEL/CentOS
based Servers then you can install it by simply using yum install lshw -y
command as shown below.
[root@localhost ~]# yum install lshw -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.mirrors.estointernet.in * epel: kartolo.sby.datautama.net.id * extras: centos.mirrors.estointernet.in * updates: centos.mirrors.estointernet.in Resolving Dependencies --> Running transaction check ---> Package lshw.x86_64 0:B.02.18-14.el7 will be installed --> Finished Dependency Resolution
If you do not have this tool installed in your Ubuntu/Debian
based Servers then you can install it by simply using apt-get install lshw
command as shown below.
root@localhost:~# apt-get install lshw Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: linux-headers-5.3.0-26 Use 'apt autoremove' to remove it. The following NEW packages will be installed: lshw 0 upgraded, 1 newly installed, 0 to remove and 150 not upgraded. Need to get 231 kB of archives. After this operation, 708 kB of additional disk space will be used.
Method 5: How to Check If a Linux Server is Physical or Virtual using hostnamectl command
In this method, you can use hostnamectl
command to check if the Server is Physical or Virtual by checking the chassis
and Virtualization
parameter as shown below. As you can see Chassis
is showing value vm
and Virtualization
is showing value kvm
which tells us that it is a Virtual Server.
[root@localhost ~]# hostnamectl status Static hostname: localhost.localdomain Transient hostname: localhost Icon name: computer-vm Chassis: vm Machine ID: f1c1e83465fa4dd2b7e3d295527d29a5 Boot ID: ae6c39f7d89b42b99e11ef940191f216 Virtualization: kvm Operating System: CentOS Linux 7 (Core) CPE OS Name: cpe:/o:centos:centos:7 Kernel: Linux 3.10.0-1127.10.1.el7.x86_64 Architecture: x86-64
Method 6: How to Check If a Linux Server is Physical or Virtual using systemd-detect-virt command
If you want to check a Unix/Linux Server is Physical or Virtual then you can use another useful tool called systemd-detect-virt
command as shown below.
[root@localhost ~]# systemd-detect-virt kvm
systemd-detect-virt
is the part of systemd
package so most probably it will be available in your Linux Server by default. You don’t have to install it manually.
For RHEL/CentOS Servers:-
[root@localhost ~]# rpm -qf $(which systemd-detect-virt) systemd-219-73.el7_8.9.x86_64
For Ubuntu/Debian Servers:-
root@localhost:~# dpkg -S $(which systemd-detect-virt) systemd: /usr/bin/systemd-detect-virt
Method 7: How to Check If a Linux Server is Physical or Virtual using virt-what command
If you want to check a Linux Server is Physical or Virtual then you can use another useful tool called virt-what
as shown below.
[root@localhost ~]# virt-what virtualbox kvm
If you do not have this tool installed in your RHEL/CentOS
based Servers then you can install it by simply using yum install virt-what -y
command as shown below.
[root@localhost ~]# yum install virt-what -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.mirrors.estointernet.in * epel: download.nus.edu.sg * extras: centos.mirrors.estointernet.in * updates: centos.mirrors.estointernet.in Resolving Dependencies --> Running transaction check ---> Package virt-what.x86_64 0:1.18-4.el7 will be installed --> Finished Dependency Resolution
If you do not have this tool installed in your Ubuntu/Debian
based Servers then you can install it by simply using apt install virt-what
command as shown below.
root@localhost:~# apt install virt-what Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: linux-headers-5.3.0-26 Use 'apt autoremove' to remove it. The following NEW packages will be installed: virt-what 0 upgraded, 1 newly installed, 0 to remove and 152 not upgraded. Need to get 14.7 kB of archives. After this operation, 39.9 kB of additional disk space will be used.
Method 8: How to Check If a Linux Server is Physical or Virtual through SYS Files
You can even check the SYS Files in your system to check if the Server is Physical or Virtual. If your system is a Virtual machine then you will see VirtualBox
value in /sys/class/dmi/id/product_name
file as shown below.
[root@localhost ~]# cat /sys/class/dmi/id/product_name VirtualBox
Method 9: How to Check If a Linux Server is Physical or Virtual Using pr command
You can also use pr
command to verify if the Server is Physical or Virtual as shown below. pr
command is used to converting text files for printing. Here we are converting /sys/class/dmi/id/sys_vendor
and /sys/class/dmi/id/product_name
files text for printing to check if the Server is Physical or Virtual.
[root@localhost ~]# pr -t /sys/class/dmi/id/sys_vendor /sys/class/dmi/id/product_name innotek GmbH VirtualBox
Method 10: How to Check If a Linux Server is Physical or Virtual Using facter command
Another method is through by using facter command as shown below. If you see kvm
in the output after running facter virtual
command then it shows it is a virtual server. Similarly if you run facter physical
command and you don’t see anything on the output then also it indicates that it is a Virtual Server.
[root@localhost ~]# facter virtual kvm [root@localhost ~]# facter physical
If you do not have this tool installed in your RHEL/CentOS
based Servers then you can install it by simply using yum install facter -y
command as shown below.
[root@localhost ~]# yum install facter -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: centos.mirrors.estointernet.in * epel: kartolo.sby.datautama.net.id * extras: centos.mirrors.estointernet.in * updates: centos.mirrors.estointernet.in Resolving Dependencies --> Running transaction check ---> Package facter.x86_64 0:2.4.1-1.el7 will be installed --> Finished Dependency Resolution
If you do not have this tool installed in your Ubuntu/Debian
based Servers then you can install it by simply using apt install facter -y
command as shown below.
root@localhost:~# apt install facter -y Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: linux-headers-5.3.0-26 Use 'apt autoremove' to remove it. The following additional packages will be installed: libboost-log1.65.1 libboost-program-options1.65.1 libboost-regex1.65.1 libcpp-hocon0.1.6 libfacter3.10.0 libleatherman-data libleatherman1.4.0 libyaml-cpp0.5v5 The following NEW packages will be installed: facter libboost-log1.65.1 libboost-program-options1.65.1 libboost-regex1.65.1 libcpp-hocon0.1.6 libfacter3.10.0 libleatherman-data libleatherman1.4.0 libyaml-cpp0.5v5 0 upgraded, 9 newly installed, 0 to remove and 152 not upgraded. Need to get 2,193 kB of archives.
Method 11: How to Check If a Linux Server is Physical or Virtual Using hwinfo command
If you want to check Linux Server is Physical or Virtual then you can use another important tool called hwinfo
. You can grep
the Product
keyword from hwinfo
command output as shown below. If it is a virtual machine then it will show under Product
section.
[root@localhost ~]# hwinfo | grep Product idProduct = 0x0001 I: Bus=0019 Vendor=0000 Product=0001 Version=0000 I: Bus=0019 Vendor=0000 Product=0003 Version=0000 I: Bus=0011 Vendor=0001 Product=0001 Version=ab41 I: Bus=0011 Vendor=0002 Product=0006 Version=0000 I: Bus=0019 Vendor=0000 Product=0006 Version=0000 I: Bus=0010 Vendor=001f Product=0001 Version=0100 Product id: "VirtualBox" Product: "VirtualBox" Product: "VirtualBox"
If you do not have this tool installed in your RHEL/CentOS
based Servers then you can install it by simply using yum install hwinfo -y
command as shown below.
[root@localhost ~]# yum install hwinfo -y Resolving Dependencies --> Running transaction check ---> Package hwinfo.x86_64 0:21.47-6.el7 will be installed --> Processing Dependency: perl(XML::Parser) for package: hwinfo-21.47-6.el7.x86_64 --> Processing Dependency: perl(XML::Writer) for package: hwinfo-21.47-6.el7.x86_64 --> Processing Dependency: libx86emu.so.1()(64bit) for package: hwinfo-21.47-6.el7.x86_64 --> Running transaction check ---> Package libx86emu.x86_64 0:1.11-7.el7 will be installed ---> Package perl-XML-Parser.x86_64 0:2.41-10.el7 will be installed ---> Package perl-XML-Writer.noarch 0:0.623-3.el7 will be installed --> Finished Dependency Resolution
If you do not have this tool installed in your Ubuntu/Debian
based Systems then you can install it by simply using apt install hwinfo -y
command as shown below.
root@localhost:~# apt install hwinfo -y Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: linux-headers-5.3.0-26 Use 'apt autoremove' to remove it. The following additional packages will be installed: libhd21 libx86emu1 The following NEW packages will be installed: hwinfo libhd21 libx86emu1 0 upgraded, 3 newly installed, 0 to remove and 152 not upgraded. Need to get 760 kB of archives.
Method 12: How to Check If a Linux Server is Physical or Virtual Using imvirt command
If you are using Ubuntu/Debian based Servers then there is a tool called imvirt
which you can use to detect if a Server is Physical or Virtual. If you see KVM in the output after running imvirt
command then it is a Virtual Machine as shown below.
root@localhost:~# imvirt KVM
If you do not have this tool installed in your Ubuntu/Debian
based Servers then you can simply install it by using apt install imvirt
command as shown below.
root@localhost:~# apt install imvirt Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: linux-headers-5.3.0-26 Use 'apt autoremove' to remove it. The following NEW packages will be installed: imvirt 0 upgraded, 1 newly installed, 0 to remove and 152 not upgraded. Need to get 4,764 B of archives.
Method 13: How to Check If a Linux Server is Physical or Virtual Using inxi command
If you are using Ubuntu/Debian based Servers then there is a tool called inxi
which you can use to detect if a Server is Physical or Virtual. If you see VirtualBox
in the output after running inxi -b
command then it is a Virtual Machine as shown below.
root@localhost:~# inxi -b System: Host: localhost Kernel: 5.4.0-42-generic x86_64 bits: 64 Console: tty 2 Distro: Ubuntu 18.04.3 LTS Machine: Device: oracle System: innotek product: VirtualBox v: 1.2 serial: 0 Mobo: Oracle model: VirtualBox v: 1.2 serial: 0 BIOS: innotek v: VirtualBox date: 12/01/2006 Battery BAT0: charge: 40.0 Wh 80.0% condition: 50.0/50.0 Wh (100%) CPU: Single core Intel Core i7-6500U (-UP-) speed: 2592 MHz (max) Graphics: Card: VMware SVGA II Adapter Display Server: X.org 1.20.4 driver: vmwgfx tty size: 168x44 Advanced Data: N/A for root out of X Network: Card: Intel 82540EM Gigabit Ethernet Controller driver: e1000 Drives: HDD Total Size: 21.5GB (53.2% used) Info: Processes: 247 Uptime: 6:01 Memory: 1146.4/1963.8MB Init: systemd runlevel: 5 Client: Shell (bash) inxi: 2.3.56
If you do not have this tool installed in your RHEL/CentOS
based Servers then you can install it by simply using yum install inxi -y
command as shown below.
[root@localhost ~]# yum install inxi -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile epel/x86_64/metalink | 5.6 kB 00:00:00 * base: centos.mirrors.estointernet.in * epel: mirror.telkomuniversity.ac.id * extras: centos.mirrors.estointernet.in * updates: centos.mirrors.estointernet.in base | 3.6 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 mysql-connectors-community | 2.5 kB 00:00:00 mysql-tools-community | 2.5 kB 00:00:00 mysql56-community | 2.5 kB 00:00:00 updates | 2.9 kB 00:00:00 Resolving Dependencies --> Running transaction check ---> Package inxi.noarch 0:3.1.03-1.el7 will be installed --> Processing Dependency: bind-utils for package: inxi-3.1.03-1.el7.noarch --> Processing Dependency: freeipmi for package: inxi-3.1.03-1.el7.noarch --> Processing Dependency: hddtemp for package: inxi-3.1.03-1.el7.noarch --> Processing Dependency: ipmitool for package: inxi-3.1.03-1.el7.noarch --> Processing Dependency: lm_sensors for package: inxi-3.1.03-1.el7.noarch --> Processing Dependency: perl(Cpanel::JSON::XS) for package: inxi-3.1.03-1.el7.noarch --> Processing Dependency: perl(JSON::XS) for package: inxi-3.1.03-1.el7.noarch --> Processing Dependency: perl(XML::Dumper) for package: inxi-3.1.03-1.el7.noarch --> Processing Dependency: usbutils for package: inxi-3.1.03-1.el7.noarch --> Processing Dependency: wmctrl for package: inxi-3.1.03-1.el7.noarch
If you do not have this tool installed in your Ubuntu/Debian
based Servers then you can simply install it by using apt install inxi -y
command as shown below.
root@localhost:~# apt install inxi -y Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: linux-headers-5.3.0-26 Use 'apt autoremove' to remove it. The following additional packages will be installed: gawk hddtemp libsigsegv2 lm-sensors mesa-utils Suggested packages: gawk-doc fancontrol read-edid i2c-tools The following NEW packages will be installed: gawk hddtemp inxi libsigsegv2 lm-sensors mesa-utils 0 upgraded, 6 newly installed, 0 to remove and 152 not upgraded. Need to get 726 kB of archives. After this operation, 2,941 kB of additional disk space will be used.
Popular Recommendations:-
How to Install PHP on Ubuntu 18.04
How to Install Ruby on Ubuntu 18.04 with Easy Steps
How to Install Ruby on CentOS/RedHat 7 in 5 Easy Steps
33 Practical Examples of ulimit command in Linux/Unix for Professionals
Install Node.js in 6 Easy Steps on Ubuntu 18.04
How to Install NVM for Node.js on Ubuntu 18.04
How to Limit CPU Limit of a Process Using CPULimit in Linux (RHEL/CentOS 7/8)
How to Install Rust Programming Language in Linux Using 6 Best Steps
5 Command to check if Server is Physical or Virtual in Linux or Unix