This PR adds a check for whether a Darwin machine is running as a QEMU guest.
Description
Apple added a Virtualization Framework based on QEMU to recent releases of macOS. This has resulted in many more options, such as UTM for organizations looking to run virtual macOS machines on Apple hardware.
One such organization appears to be Github, which seems to be adding Veertu VMs to their Github Actions runners. Unfortunately, Chef's virtual? helper fails to detect these machines as guests, since ohai isn't setting the role for QEMU VMs.
The XNU kernel added an Object ID named kern.hv_vmm_present, which returns 0 for physical hardware and 1 for virtual machines. This OID is present on x86 devices running macOS Big Sur (version 11) and all Apple ARM macOS devices. By shelling out to sysctl, we can use this OID to detect VMs.
Types of changes
[ ] Bug fix (non-breaking change which fixes an issue)
[x] New feature (non-breaking change which adds functionality)
[ ] Breaking change (fix or feature that would cause existing functionality to change)
[ ] Chore (non-breaking change that does not add functionality or fix an issue)
Checklist:
[x] I have read the CONTRIBUTING document.
[x] I have run the pre-merge tests locally and they pass.
[x] I have updated the documentation accordingly.
[x] I have added tests to cover my changes.
[x] If Gemfile.lock has changed, I have used --conservative to do it and included the full output in the Description above.
This PR adds a check for whether a Darwin machine is running as a QEMU guest.
Description
Apple added a Virtualization Framework based on QEMU to recent releases of macOS. This has resulted in many more options, such as UTM for organizations looking to run virtual macOS machines on Apple hardware.
One such organization appears to be Github, which seems to be adding Veertu VMs to their Github Actions runners. Unfortunately, Chef's
virtual?
helper fails to detect these machines as guests, sinceohai
isn't setting the role for QEMU VMs.The XNU kernel added an Object ID named kern.hv_vmm_present, which returns 0 for physical hardware and 1 for virtual machines. This OID is present on x86 devices running macOS Big Sur (version 11) and all Apple ARM macOS devices. By shelling out to
sysctl
, we can use this OID to detect VMs.Types of changes
Checklist:
Gemfile.lock
has changed, I have used--conservative
to do it and included the full output in the Description above.