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
    
目录
相关文章
|
存储 安全 虚拟化
虚拟机检测技术剖析
作者:riusksk (泉哥) 主页:http://riusksk.blogbus.com 前言 在当今信息安全领域,特别是恶意软件分析中,经常需要利用到虚拟机技术,以提高病毒分析过程的安全性以及硬件资源的节约性,因此它在恶意软件领域中是应用 越来越来广泛。
1266 0
|
2月前
|
虚拟化
vmware克隆虚拟机后没有ip地址的问题
解决vmware克隆虚拟机后没有内网ip的问题
|
3月前
|
SQL 存储 数据挖掘
【虚拟机数据恢复】VMware虚拟机文件被误删除的数据恢复案例
虚拟机数据恢复环境: 某品牌R710服务器+MD3200存储,上层是ESXI虚拟机和虚拟机文件,虚拟机中存放有SQL Server数据库。 虚拟机故障: 机房非正常断电导致虚拟机无法启动。服务器管理员检查后发现虚拟机配置文件丢失,所幸xxx-flat.vmdk磁盘文件和xxx-000001-delta.vmdk快照文件还在。服务器管理员在尝试恢复虚拟机的过程中,将原虚拟机内的xxx-flat.vmdk删除后新建了一个虚拟机,并分配了精简模式的虚拟机磁盘和快照数据盘,但原虚拟机内的数据并没有恢复。
【虚拟机数据恢复】VMware虚拟机文件被误删除的数据恢复案例
|
Linux 虚拟化 数据安全/隐私保护
VMware使用 - 虚拟机克隆
如果已经安装了一台Linux操作系统,没有必要重新安装,只需要克隆就可以了,有两种方式。
23 0
|
4月前
|
存储 网络协议 虚拟化
如何操作VMware ESXi虚拟机的迁移?
如何操作VMware ESXi虚拟机的迁移?
196 1
|
4月前
|
存储 虚拟化 数据中心
如何操作VMware ESXi虚拟机的克隆?
如何操作VMware ESXi虚拟机的克隆?
86 1
|
3月前
|
Linux 虚拟化 数据安全/隐私保护
【Linux】VMware安装虚拟机- Windows + Linux
【1月更文挑战第20天】【Linux】VMware安装虚拟机- Windows + Linux
|
29天前
|
算法 虚拟化 C++
VMware虚拟机无法自适应和拖拽复制粘贴和共享目录问题
VMware虚拟机无法自适应和拖拽复制粘贴和共享目录问题
87 0