5 ways to check if server is physical or virtual in Linux or Unix


Linux, Tips and Tricks

Earlier I shared the steps to allocate resource using cgroups and slice in Linux. Now with this article I will share different commands and files which can be used to check if server is physical or virtual on Linux and Unix platform. You can use the commands and from this article to check if server is physical or virtual either remotely or by directly connecting to the console of the server. There can be many more commands but these are some which I use on a day to day basis, if you know of any more commands then please do share in the comments section.

 

Check if server is Physical or Virtual

Below are list of some of the commands which can be used to check if server is physical or virtual

 

Method-1: lshw

Below are some sample outputs

On Physical Machine

# lshw -c system | grep product
    product: ProLiant BL460c Gen9 (776320-B21)
       product: PnP device PNP0b00
       product: PnP device PNP0c02

 

For Virtual Machine

# lshw -c system
director.example
    description: Computer
    product: KVM
    vendor: Red Hat
    version: RHEL 7.0.0 PC (i440FX + PIIX, 1996)
    width: 64 bits
    capabilities: smbios-2.4 dmi-2.4 smp vsyscall32


# lshw -c system | grep -i product
    product: VMware Virtual Platform
       product: PnP device PNP0c02
       product: PnP device PNP0b00
       product: PnP device PNP0103
       product: PnP device PNP0c02

 

Method-2: dmicecode

Below are some sample outputs

On Physical machine

# dmidecode -t system
# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 2.8 present.

Handle 0x0009, DMI type 1, 27 bytes
System Information
        Manufacturer: HP
        Product Name: ProLiant BL460c Gen9
        Version: Not Specified
        Serial Number: SGH709S31R
        UUID: 33363737-3032-4753-4837-303953333152
        Wake-up Type: Power Switch
        SKU Number: 776320-B21
        Family: ProLiant
		
# dmidecode -t system
# dmidecode 2.12
SMBIOS 2.5 present.

Handle 0x0001, DMI type 1, 27 bytes
System Information
        Manufacturer: FUJITSU
        Product Name: PRIMERGY RX200 S6
        Version: GS01
        Serial Number: YL6S001919
        UUID: 00000000-0000-0000-0000-00262D04D2F6
        Wake-up Type: Power Switch
        SKU Number: ABN:K1342-V101-2
        Family: SERVER

 

On Virtual Machine

# dmidecode -t system
# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 2.4 present.

Handle 0x0100, DMI type 1, 27 bytes
System Information
        Manufacturer: Red Hat
        Product Name: KVM
        Version: RHEL 7.0.0 PC (i440FX + PIIX, 1996)
        Serial Number: Not Specified
        UUID: 7283C294-6449-404A-86EB-3CD3F6922773
        Wake-up Type: Power Switch
        SKU Number: Not Specified
        Family: Red Hat Enterprise Linux

# dmidecode -t system
# dmidecode 3.0
Getting SMBIOS data from sysfs.
SMBIOS 2.5 present.

Handle 0x0001, DMI type 1, 27 bytes
System Information
        Manufacturer: innotek GmbH
        Product Name: VirtualBox
        Version: 1.2
        Serial Number: 0
        UUID: 43F05102-8378-4C85-8D39-E38E358B4669
        Wake-up Type: Power Switch
        SKU Number: Not Specified
        Family: Virtual Machine

 

Method-3: dmesg file

Below are some sample outputs

On Physical Machine

# dmesg | grep DMI
[    0.000000] DMI: HP ProLiant BL460c Gen9, BIOS I36 02/17/2017

# dmesg | grep DMI
[    0.000000] DMI present.
[    0.000000] DMI: FUJITSU   PRIMERGY RX200 S6   /D3031, BIOS 6.00 Rev. 1.10.3031   01/20/2012

 

On Virtual Machine

# dmesg | grep DMI
[    0.000000] DMI: Red Hat KVM, BIOS 0.5.1 01/01/2011

# dmesg | grep DMI
[    0.000000] DMI: innotek GmbH VirtualBox/VirtualBox, BIOS VirtualBox 12/01/2006

 

Method-4: System Files under /sys/class/dmi/id/*

node1:~ # cd /sys/class/dmi/id
node1:/sys/class/dmi/id # ls -l
total 0
-r--r--r-- 1 root root 4096 Sep 19 21:06 sys_vendor
-r--r--r-- 1 root root 4096 Sep 19 21:06 product_name
-r--r--r-- 1 root root 4096 Sep 19 21:06 bios_vendor
-rw-r--r-- 1 root root 4096 Sep 19 21:06 uevent
-r--r--r-- 1 root root 4096 Sep 19 21:06 modalias
drwxr-xr-x 2 root root    0 Sep 19 21:09 power
-r--r--r-- 1 root root 4096 Sep 19 21:09 product_version
-r-------- 1 root root 4096 Sep 19 21:09 product_uuid
-r-------- 1 root root 4096 Sep 19 21:09 product_serial
-r--r--r-- 1 root root 4096 Sep 19 21:09 chassis_version
-r--r--r-- 1 root root 4096 Sep 19 21:09 chassis_vendor
-r--r--r-- 1 root root 4096 Sep 19 21:09 chassis_type
-r-------- 1 root root 4096 Sep 19 21:09 chassis_serial
-r--r--r-- 1 root root 4096 Sep 19 21:09 chassis_asset_tag
-r--r--r-- 1 root root 4096 Sep 19 21:09 bios_version
-r--r--r-- 1 root root 4096 Sep 19 21:09 bios_date
lrwxrwxrwx 1 root root    0 Sep 28 16:37 subsystem -> ../../../../class/dmi

 

Below are some sample outputs

On Physical Machine

# cat /sys/class/dmi/id/product_name
PRIMERGY RX200 S6

# cat /sys/class/dmi/id/chassis_vendor
FUJITSU
# cat /sys/class/dmi/id/product_name
ProLiant BL460c Gen9

# cat /sys/class/dmi/id/sys_vendor
HP

 

On Virtual Machine

# cat /sys/class/dmi/id/sys_vendor
Red Hat

# cat /sys/class/dmi/id/product_name
KVM
# cat /sys/class/dmi/id/chassis_vendor
Oracle Corporation

# cat /sys/class/dmi/id/product_name
VirtualBox
# cat /sys/class/dmi/id/sys_vendor
VMware, Inc.

# cat /sys/class/dmi/id/product_name
VMware Virtual Platform

 

Method-5: hwinfo

Below are some sample outputs

On Physical Machine

# hwinfo --all --log ~/hwinfo_dump.txt

Next go through the file to get the hardware details, below is a sample snippet

  system.hardware.vendor = 'HP'
  system.hardware.product = 'ProLiant BL460c Gen9'
  system.hardware.version = ''
  system.chassis.manufacturer = 'HP'
# hwinfo --all --log ~/hwinfo_dump.txt

Next go through the file to get the hardware details, below is a sample snippet

  system.hardware.vendor = 'FUJITSU'
  system.hardware.product = 'PRIMERGY RX200 S6'
  system.hardware.version = 'GS01'
  system.chassis.manufacturer = 'FUJITSU'
  system.board.product = 'D3031'
  system.board.version = 'S26361-D3031-A100 WGS02 GS0'
  system.board.vendor = 'FUJITSU'
  system.chassis.type = 'Rack Mount Chassis'

 

On Virtual Machine

# hwinfo --all --log ~/hwinfo_dump.txt

Next go through the file to get the hardware details, below is a sample snippet

  system.firmware.release_date = '09/30/2014'
  system.hardware.vendor = 'VMware, Inc.'
  system.hardware.product = 'VMware Virtual Platform'
  system.hardware.version = 'None'
  system.chassis.manufacturer = 'No Enclosure'
  system.board.product = '440BX Desktop Reference Platform'
  system.board.version = 'None'
  system.board.vendor = 'Intel Corporation'
  system.chassis.type = 'Other'
  system.formfactor = 'unknown'

 

Lastly I hope the commands from this article to check if server is physical or virtual in Linux or Unix was helpful. So, let me know your suggestions and feedback using the comment section.

Deepak Prasad

Deepak Prasad

He is the founder of GoLinuxCloud and brings over a decade of expertise in Linux, Python, Go, Laravel, DevOps, Kubernetes, Git, Shell scripting, OpenShift, AWS, Networking, and Security. With extensive experience, he excels in various domains, from development to DevOps, Networking, and Security, ensuring robust and efficient solutions for diverse projects. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

1 thought on “5 ways to check if server is physical or virtual in Linux or Unix”

  1. With help of these command you can get your system is physical or virtual.
    factor virtual , virt-what , systemd-detect-virtual

    Reply

Leave a Comment