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

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...




你可能感兴趣的:(dmidecode,lshw)