How to determine if a script is running in a virtual machine?

I do not think that the question needs any explanation. I am writing software that can load virtual machines to simulate a network. I would like to disable this feature if the software is already running on a virtual machine.

I already read this post: How to determine if my application is running on a virtual machine? But I need to do this on Linux, and this post covers only Windows.

I put it as a Perl question, since I have to do it in Perl, but there is probably a file in proc or somewhere else to check, and it is the same for all languages. Actually I do not know.

I am interested in discovering mainly VirtualBox and KVM, as these are the virtual machines that I use.

So, any suggestion?

+7
source share
3 answers

I will talk specifically about VMware and Virtual Box virtual machines running Linux as a guest operating system. If you run the command below, you will find out that the underlying hardware is VMware / VirtualBox, which confirms that it is a virtual machine.

For VMware guests:

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

For guest Virtual Box:

 # dmidecode | grep -i product Product Name: VirtualBox 

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

I do not have another hypervisor at my disposal to get what returns above the command.

Hope this helps.

+11
source

Google quick income dmo.ca/blog/How to detect virtualization

Perl module and all.

+3
source

Have you tried Sys :: Detect :: Virtualization available in CPAN?

+1
source

All Articles