Add preflight check for hardware-assisted virtualization #644
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem:
We need to make sure the host we're installing on supports hardware-assisted virtualization.
Solution:
This is pretty quick and dirty, but I hope should not be unreasonable. https://help.ubuntu.com/community/KVM/Installation tells us that we need to run
egrep -c '(vmx|svm)' /proc/cpuinfo
to check for hardware-assisted virtualization on x86_64 systems, but I think we can short-circuit that.I reviewed the kvm-ok script (https://bazaar.launchpad.net/~cpu-checker-dev/cpu-checker/trunk/view/head:/kvm-ok) and it first checks for those CPU flags, and then next checks for the existence of /dev/kvm. If both succeed, we're good. But I don't think we actually need the CPU flag check, at least on SUSE distros. I did some testing, and AFAICT if the CPU supports hardware virtualization, the appropriate kvm kernel module (e.g. kvm_intel) is loaded automatically, so /dev/kvm will exist. If not, the module doesn't get loaded and /dev/kvm doesn't exist.
More recent changes to kvm-ok in Debian-based distros (see https://sources.debian.org/patches/cpu-checker/0.7-1.3/) add support for other architectures (aarch64, ppc*, s390x, riscv64), but in all those cases, the only thing that happens is a check for the existence of /dev/kvm.
Related Issue:
harvester/harvester#1154
Test plan:
N/A (should be covered by unit tests in this PR)