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:
For guest Virtual Box:
" 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.
slayedbylucifer
source share