如何判断当前系统运行在物理机上还是虚拟机上,返回虚拟机的类型

virt-what

一般系统都会自带virt-what,若程序没带的话 自己下载安装即可

[root@localhost ~]# yum install virt-what

[root@localhost ~]# virt-what
vmware

 用lspci -b|grep "VMware"抓取系列信息,即表明此系统的宿主机是基于VMware虚拟出来的,别的可以

[root@localhost ~]# lspci -b|grep "VMware"
00:07.7 System peripheral: VMware Virtual Machine Communication Interface (rev 10)
00:0f.0 VGA compatible controller: VMware SVGA II Adapter
00:11.0 PCI bridge: VMware PCI bridge (rev 02)
00:15.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:15.7 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:16.7 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:17.7 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.0 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.1 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.2 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.3 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.4 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.5 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.6 PCI bridge: VMware PCI Express Root Port (rev 01)
00:18.7 PCI bridge: VMware PCI Express Root Port (rev 01)
02:00.0 USB controller: VMware USB1.1 UHCI Controller
02:03.0 USB controller: VMware USB2 EHCI Controller

还可以用 dmesg 和 dmidecode  均有以下字样

[root@localhost ~]# dmesg | grep VMware
[    0.000000] DMI: VMware, Inc. VMware Virtual Platform/440BX Desktop Reference Platform, BIOS 6.00 04/13/2018
[    0.000000] Hypervisor detected: VMware
[    0.000000] Booting paravirtualized kernel on VMware hypervisor
[    2.486307] input: VirtualPS/2 VMware VMMouse as /devices/platform/i8042/serio1/input/input2
[    2.488088] input: VirtualPS/2 VMware VMMouse as /devices/platform/i8042/serio1/input/input3
[    2.900512] usb 2-1: Product: VMware Virtual USB Mouse
[    2.900516] usb 2-1: Manufacturer: VMware
[    2.911424] input: VMware VMware Virtual USB Mouse as /devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/2-1/2-1:1.0/input/input4
[    2.911718] hid-generic 0003:0E0F:0003.0001: input,hidraw0: USB HID v1.10 Mouse [VMware VMware Virtual USB Mouse] on usb-0000:02:00.0-1/input0
[    3.163066] usb 2-2: Product: VMware Virtual USB Hub
[    8.059298] scsi 0:0:0:0: Direct-Access     VMware,  VMware Virtual S 1.0  PQ: 0 ANSI: 2
[    8.278897] ata2.00: ATAPI: VMware Virtual IDE CDROM Drive, 00000001, max UDMA/33
[    8.299589] scsi 2:0:0:0: CD-ROM            NECVMWar VMware IDE CDR10 1.00 PQ: 0 ANSI: 5
[root@localhost ~]# dmidecode | grep VMware
    Manufacturer: VMware, Inc.
    Product Name: VMware Virtual Platform
    Serial Number: VMware-56 4d c4 fe d0 45 68 cc-5e e3 70 9c 38 e8 a2 3f
    Description: VMware SVGA II

 Windows:

在CMD里输入:Systeminfo | findstr /i "System Model"
如果System Model:后面含有Virutal就是虚拟机,其他都是物理机
或者用powershell命令:get-wmiobject win32_computersystem | fl model

Linux:

在bash里输入:dmidecode -s system-product-name
或者lshw -class system
或者dmesg | grep -i virtual

猜你喜欢

转载自www.cnblogs.com/navysummer/p/11002112.html