检查服务器在Linux或者Unix中是物理的还是虚拟的

时间:2020-01-09 10:37:38  来源:igfitidea点击:

在本文中,我将共享不同的命令和文件,这些命令和文件可用于"检查服务器在Linux和Unix平台上是物理的还是虚拟的"。我们可以使用命令,从本文开始,可以通过远程或者直接连接到服务器的控制台来检查服务器是物理服务器还是虚拟服务器。可能还有更多命令,但是我每天都会使用这些命令,如果我们知道更多命令,请在注释部分中分享。

检查服务器是物理服务器还是虚拟服务器

以下是一些可用于检查服务器是物理服务器还是虚拟服务器的命令的列表

sh

以下是一些示例输出

在物理机上

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

对于虚拟机

# 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

dmicecode

以下是一些示例输出

在物理机上

# 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

在虚拟机上

# 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

dmesg文件

以下是一些示例输出

在物理机上

# dmesg | grep DMI
[    0.000000] DMI: HP ProLiant BL460c Gen9, BIOS I36 02/17/2016
# 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

在虚拟机上

# 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

###/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

以下是一些示例输出

在物理机上

# 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

在虚拟机上

# 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

hwinfo

以下是一些示例输出

在物理机上

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

接下来浏览文件以获取硬件详细信息,以下是示例代码段

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

接下来浏览文件以获取硬件详细信息,以下是示例代码段

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'

在虚拟机上

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

接下来浏览文件以获取硬件详细信息,以下是示例代码段

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'