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

陌路散爱 提交于 2019-12-03 22:52:52

方法一: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

举例如下:

###这是阿里云的云主机
[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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!