How to detect if the script is running on a virtual machine?

别来无恙 提交于 2019-12-04 03:12:37

I will talk specific to VMware and virtual Box Virtual Machines running Linux as guest Operating system. If you run below command, you will come to know that the underlying hardware is VMware/VirtualBox which certifies that it is a Virtual Machine.

For VMware guest:

# dmidecode  | grep -i product
        Product Name: VMware Virtual Platform

For Virtual Box guest:

# dmidecode  | grep -i product
    Product Name: VirtualBox

"dmidecode" is a linux system command. You can have perl run dmidecode in the beginning of your script and extract the value. If it is a virtual machine then the script should exit without any further execution.

I do not have any other hypervisor at my disposal to get you what above command return on them.

Hope this helps.

A quick Google yields dmo.ca/ blog/ How to detect virtualization

Perl module and everything.

Have you tried Sys::Detect::Virtualization, available on CPAN?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!