detecting if my process is running on a virtual macos x instance and not on my local mac machine

I m trying to identify if my launched process is running on a local mac machine(desktop/laptop) or a virtual macOS X instance like AWS EC2, Azure, MacStadium etc.

I have followed this link which searched for its limited providers in the output, but I m not bound to any limited providers and looking for a general solution which is applicable to all the providers.

Is there some hardware/network/virtualization-related information that can be used to identify if the process is launched on a virtual MacOS instance?

OR is there some system Information that I can use to be sure that my process is running on a local machine?

Answered by DTS Engineer in 767186022

This works in all the VM environments I use day-to-day:

  • VMware Fusion:

    % sysctl kern.hv_vmm_present
    kern.hv_vmm_present: 1
    
  • QEMU:

    % sysctl kern.hv_vmm_present
    kern.hv_vmm_present: 1
    
  • Virtualization framework:

    % sysctl kern.hv_vmm_present
    kern.hv_vmm_present: 1
    

If it’s not working for a specific virtual machine platform, I recommend that you raise that with the platform vendor.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Standard practice here is to check for the kern.hv_vmm_present sysctl. You can do this from command line:

% sysctl kern.hv_vmm_present
kern.hv_vmm_present: 0

or with the sysctlbyname API.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

I tried running sysctl kern.hv_vmm_present on the terminal in Amazon EC2 VM, however it does not give the right output. Even on a cloud VM it returns kern.hv_vmm_present: 0. Any reasons why or how can I identify the process running on VM?

Accepted Answer

This works in all the VM environments I use day-to-day:

  • VMware Fusion:

    % sysctl kern.hv_vmm_present
    kern.hv_vmm_present: 1
    
  • QEMU:

    % sysctl kern.hv_vmm_present
    kern.hv_vmm_present: 1
    
  • Virtualization framework:

    % sysctl kern.hv_vmm_present
    kern.hv_vmm_present: 1
    

If it’s not working for a specific virtual machine platform, I recommend that you raise that with the platform vendor.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

detecting if my process is running on a virtual macos x instance and not on my local mac machine
 
 
Q