开发者社区> cnbird> 正文

How to detect virtualization 虚拟机检测

简介: 除了下面的方法外,mac地址也可以检测虚拟机。Update: You may be interested in [[the perl module|perl-module-for-virtualization-detection]] implementing these tricks.
+关注继续查看

除了下面的方法外,mac地址也可以检测虚拟机。
Update: You may be interested in [[the perl module|perl-module-for-virtualization-detection]] implementing these tricks.

Frequently, our customers want to install our software in a virtual machine. This can be OK, but frequently they hit a CPU, memory, or IO limit caused by running in a constrained virtual environment. When this happens, we really like to know if they’re running under virtualization when we try to support them. Here’s some tricks to detect, from a shell, if the system is virtualized.

The first thing to check is dmesg. On a recently-booted system, checking the ‘dmesg’ command output may be sufficient. Otherwise, try “cat /var/log/dmesg” instead of “dmesg”

 

  • VMWare:
     # dmesg | grep -i virtual
     VMware vmxnet virtual NIC driver
       Vendor: VMware    Model: Virtual disk      Rev: 1.0
     hda: VMware Virtual IDE CDROM Drive, ATAPI CD/DVD-ROM drive
    
  • QEmu or KVM:If the “-cpu host” option has not been used, QEmu and KVM will identify themselves as:
     # dmesg | grep -i virtual
     CPU: AMD QEMU Virtual CPU version 0.9.1 stepping 03
    

    otherwise, the host’s CPU information will be used both in dmesg, or in /proc/cpuinfo.

    However, you should see something like:

     $ dmesg | grep -i virtual
     [    0.000000] Booting paravirtualized kernel on KVM
    

    on newer kernels that understand that they’re running under paravirtualization. (Thanks to René Pfeiffer for pointing this out)

  • Microsoft VirtualPC:
     # dmesg | grep -i virtual
     hda: Virtual HD, ATA DISK drive
     hdc: Virtual CD, ATAPI CD/DVD-ROM drive
    
  • Xen (thanks, wardi and others)
    # dmesg | grep -i xen
    Xen virtual console successfully installed as tty1
    
  • Virtuozzo
    # dmesg
    (returns no output)
    
    # cat /var/log/dmesg
    (returns no output)
    
    # ls -al /proc/vz
    veinfo  veinfo_redir  veredir  vestat  vzaquota  vzdata
    

On longer-running systems, you may need to grep /var/log/dmesg instead.

If that doesn’t produce anything useful, try using dmidecode to look at the BIOS information. Frequently, there will be at least one component identifying itself as virtualized:

  • VMWare:
     # dmidecode | egrep -i 'manufacturer|product'
     Manufacturer: VMware, Inc.
     Product Name: VMware Virtual Platform
    
  • Microsoft VirtualPC:
     # dmidecode | egrep -i 'manufacturer|product'
     Manufacturer: Microsoft Corporation
     Product Name: Virtual Machine
    
  • QEMU or KVM:
     # dmidecode | egrep -i 'vendor'
     Vendor: QEMU
    
  • Virtuozzo:
     # dmidecode
     /dev/mem: Permission denied
    
  • Xen:
     # dmidecode | grep -i domU
           Product Name: HVM domU
    

You should just examine the output of dmidecode directly rather than trying to grep as above, in case the output changes. QEMU, for example, doesn’t report the vendor in all versions.

Next, check disk devices for identification as virtualized:

  • VMWare:
    # cat /proc/ide/hd*/model
    VMware Virtual IDE CDROM Drive
    # cat /proc/scsi/scsi
    Attached devices:
    Host: scsi0 Channel: 00 Id: 00 Lun: 00
      Vendor: VMware   Model: Virtual disk     Rev: 1.0
      Type:   Direct-Access                    ANSI SCSI revision: 02
    
  • Microsoft VirtualPC:
    # cat /proc/ide/hd*/model
    Virtual HD
    Virtual CD
    
  • QEMU, KVM, or Xen:
    # cat /proc/ide/hd*/model
    QEMU HARDDISK
    QEMU DVD-ROM
    
  • Virtuozzo:
    # ls -al /dev/vzfs
    b-----x--- 1 root root 0, 19 2009-04-06 15:04 /dev/vzfs
    

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
Virtual PC虚拟机怎样退出全屏模式
右边的ALT+Enter键 同时按下去
1345 0
阿里云服务器如何登录?阿里云服务器的三种登录方法
购买阿里云ECS云服务器后如何登录?场景不同,阿里云优惠总结大概有三种登录方式: 登录到ECS云服务器控制台 在ECS云服务器控制台用户可以更改密码、更换系.
28076 0
Mac 下解决虚拟机virtualbox 4.3和windows共享问题
mac上面安装了最新的virtualbox,有些软件还是需要windows的。 1,在设置了共享之后,仍然不能使用  不能共享 2,找了半天发现需要windows安装 VBoxGuestAdditions_4.3.8.iso http://download.virtualbox.org/virtualbox/4.3.8/VBoxGuestAdditions_4.3.8.is
660 0
阿里云服务器端口号设置
阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
20148 0
阿里云服务器怎么设置密码?怎么停机?怎么重启服务器?
如果在创建实例时没有设置密码,或者密码丢失,您可以在控制台上重新设置实例的登录密码。本文仅描述如何在 ECS 管理控制台上修改实例登录密码。
23538 0
virtualbox中ubuntu虚拟机安装增强功能
virtualbox中ubuntu虚拟机安装增强功能
78 0
+关注
cnbird
阿里云安全专家,主要负责阿里云云产品安全。
4033
文章
3
问答
文章排行榜
最热
最新
相关电子书
更多
JS零基础入门教程(上册)
立即下载
性能优化方法论
立即下载
手把手学习日志服务SLS,云启实验室实战指南
立即下载