判断当前主机是物理机还是虚拟机

Windows:


    1 Systeminfo | findstr /i "System Model"



    如果System Model:后面含有Virutal就是虚拟机,其他都是物理机


    2 powershell命令:get-wmiobject win32_computersystem | fl model



Linux:


    1 dmidecode -s system-product-name或dmidecode | grep Product

ubuntu 14 ppc64le
# dmidecode -s system-product-name
dmidecode: command not found

ubuntu 14 x86_64
# dmidecode -s system-product-name
KVM

rhel6 x86_64
# dmidecode -s system-product-name
System x3650 M3 -[7945J2A]-

# dmidecode | grep Product
        Product Name: System x3650 M3 -[7945J2A]-
        Product Name: 86Y2329

    2 lshw -class system

ubuntu 14 ppc64le
# lshw -class system
docker-new2
    description: Computer
    product: IBM pSeries (emulated by qemu)
    width: 64 bits


ubuntu 14 x86_64

# lshw -class system
xcontainer3
    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 vsyscall32
    configuration: boot=normal family=Red Hat Enterprise Linux uuid=0C2859ED-1E26-495A-83E0-16206ADC82E5


rhel6 x86_64

# lshw -class system
-bash: lshw: command not found

    3 dmesg | grep -i virtual

ubuntu 14 ppc64le
~# dmesg | grep -i virtual
[    0.000000] Page orders: linear mapping = 16, virtual = 16, io = 12, vmemmap = 16
[    0.206961] IOMMU table initialized, virtual merging enabled
[    0.739987] scsi host0: IBM POWER Virtual SCSI Adapter 1.5.9
[    0.935985] ibmveth: IBM Power Virtual Ethernet Driver 1.04

ubuntu 14 x86_64
# dmesg | grep -i virtual
[    0.000000] Booting paravirtualized kernel on KVM
[    0.040002] smpboot: CPU0: Intel QEMU Virtual CPU version 1.5.3 (fam: 06, model: 0d, stepping: 03)
[    0.051554] KVM setup paravirtual spinlock

rhel6 x86_64
# dmesg | grep -i virtual
Booting paravirtualized kernel on bare hardware
input: Macintosh mouse button emulation as /devices/virtual/input/input1

物理机
[root@zhai ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@zhai ~]#
[root@zhai ~]# dmesg | grep -i virtual
[    0.000000] Booting paravirtualized kernel on bare hardware
[    3.184433] systemd[1]: Starting Setup Virtual Console...
[    3.245077] systemd[1]: Started Setup Virtual Console.
[    5.543025] scsi 1:0:0:0: CD-ROM            IMM      Virtual Media    0325 PQ: 0 ANSI: 0

KVM:
[root@ansible ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.1 (Maipo)
[root@ansible ~]# dmesg | grep -i virtual
[    0.000000] Booting paravirtualized kernel on KVM
[    0.027027] KVM setup paravirtual spinlock
[    0.689505] systemd[1]: Detected virtualization 'kvm'.
[    0.753430] systemd[1]: Starting Setup Virtual Console...




  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值