判断我们的服务器是物理机还是虚拟机

时间:2022-07-27 21:48:35

突然有一天,有人问,这台设备是物理机还是虚拟机,我就懵逼了。

很简单,这里写一下,以后查起来方便。

方法一:dmesg

举例如下:

###这是阿里云的云主机
[root@xxx ~]# dmesg |grep -i virtual
[    0.000000] Booting paravirtualized kernel on KVM
[    0.707486] KVM setup paravirtual spinlock
[    1.811087] input: VirtualPS/2 VMware VMMouse as /devices/platform/i8042/serio1/input/input2
[    1.811257] input: VirtualPS/2 VMware VMMouse as /devices/platform/i8042/serio1/input/input3
[    1.824106] systemd[1]: Detected virtualization kvm.
[    1.853583] systemd[1]: Starting Setup Virtual Console...
###这是一台物理机
[root@xxx]# dmesg |grep -i virtual
Booting paravirtualized kernel on bare hardware
input: Macintosh mouse button emulation as /devices/virtual/input/input1

 

方法二:dmidecode 

举例如下:

###这是阿里云的云主机
[root@xxx~]# dmidecode -s system-product-name
Alibaba Cloud ECS
###这是一台物理机
[root@xxx]# dmidecode -s system-product-name
PowerEdge R720