Linux判断当前机器是虚拟机还是物理机--dmidecode命令

术语(自行google,baidu)

  • DMI
    DMI (Desktop Management Interface, DMI)的主要组成部分是Management InformationFormat (MIF)数据库。这个数据库包括了所有有关电脑系统和配件的信息。通过DMI,用户可以获取序列号、电脑厂商、串口信息以及其它系统配件信息。

  • SMBIOS
    System Management BIOS,SMBIOS
    SMBIOS(System Management BIOS)是主板或系统制造者以标准格式显示产品管理信息所需遵循的统一规范。


dmidecode命令

ubuntu下 man dmidecode的解释

dmidecode is a tool for dumping a computer’s DMI (some say SMBIOS) table contents in a human-readable format. This table contains a description of the system’s hardware components, as well as other useful pieces of information such as serial numbers and BIOS revision. Thanks to this table, you can retrieve this information without having to probe for the actual hardware. While this is a good point in terms of report speed and safeness, this also makes the presented information possibly unreliable.

所以,dmidecode允许你在Linux系统下获取有关硬件方面的信息。dmidecode遵循SMBIOS/DMI标准,其输出的信息包括BIOS、系统、主板、处理器、内存、缓存等等。


今天工作中遇到了这个问题,特此记录,shell判断脚本函数如下(可能要注意运行权限)

# return 1 is viruual machine
# return 0 not
function IsVirtualMachine()
{
        dmidecode -s system-product-name | grep -i "virtual"
        if [ $? -eq 0 ]; then
                return 1
        fi
        return 0
}

在qemu kvm, vmware 虚拟机下测试通过,可以判断。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值