Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating check for Hyper-V #9471

Closed
wants to merge 2 commits into from

Conversation

PatrickLang
Copy link
Contributor

This is an updated check to tell if a hypervisor (including Hyper-V) is running on Windows. Virtualbox uses this check to avoid crashing (See #9258).

This fix covers a few more corner cases than the previous one in #9456:

  • Allow virtualbox to run if Hyper-V is installed, but currently disabled. If you want to switch a machine between using Virtualbox and Hyper-V, you can do it with another boot entry - Link
  • Works on Windows Server & Windows 10. Windows Server uses Get-WindowsFeature to check for install, while Get-WindowsOptionalFeature is used on Windows 10 ¯\(ツ)
  • There are two other features that use the hypervisor, so it's possible to have it loaded but Microsoft-HyperV-All isn't installed: Windows-Defender-ApplicationGuard, and DeviceGuard which is controlled through group policy

@briancain briancain self-assigned this Feb 16, 2018
@briancain briancain self-requested a review February 16, 2018 17:34
@PatrickLang
Copy link
Contributor Author

PatrickLang commented Feb 16, 2018

Oops sorry about that. Need to read up on Ruby unit testing. I think the commit I added should fix it.

My manual test on a win10 laptop with Hyper-V enabled works as expected

>vagrant up --provider=virtualbox
The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system. The
reason is shown below:

Hyper-V and VirtualBox cannot be used together and will result in a
system crash. Vagrant will now exit. Please disable Hyper-V if you wish
to use VirtualBox.

@briancain
Copy link
Member

@PatrickLang - Thanks for the update! A couple of questions...

Is there a better check for seeing if Hyper-V is "installed" but disabled? Also do you have an example of how to get to that state in windows 10? Every bit of documentation I see says that it's either enabled or disabled, but I see no language around it being installed but "off". I ask because this command:

$(Get-ComputerInfo).HypervisorPresent

Won't work for this because it returns true if you're running vagrant on Windows inside of a virtual machine. :(

We will however need some sort of check to ensure that this is only checked against windows 10 (maybe windows 8 works?), because these commands fail and do not exist on older systems like windows 7.

@briancain
Copy link
Member

Edit on this: I just tried this on windows 7. We will be fine without a OS check, as the Powershell.execute_cmd function returns nil if a command fails (i.e. doesn't exist).

@PatrickLang
Copy link
Contributor Author

Here's the corner cases I can think of:

Windows 7 - check should always fail. Hyper-V not present, and check for it isn't there
Windows 8 / Windows Server 2012 - check should work. If Hyper-V is present, the check should do the right thing.

One false positive would be:
Windows 8+ or Windows Server 2012+ running under VMWare, KVM or Xen. Those will also return Hypervisor present. If Virtualbox works nested under those hypervisors, then we should switch to a per-hypervisor check which will be much more difficult. You'd have to look at what devices are present to guess what hypervisor you're under and of course hypervisors can lie :/

@briancain
Copy link
Member

So yesterday I did some tests. We should be good without a "check" for which OS we're on, because if the powershell command fails, its helper function in Vagrant will just return nil so we won't have to worry about an uncaught exception for a command that doesn't exist on Windows 7. The original check will just be false, and we should be good to continue on using the virtualbox provider.

Finally that being said, I'm still pretty confident that the check in place is enough to determine if Hyper-V is running...but I might be missing something.

$(Get-WindowsOptionalFeature -FeatureName Microsoft-Hyper-V-All -Online).State

This returns either Enabled or Disabled. I'm assuming if it's Enabled, Hyper-V is running, and therefore Vagrant needs to bail out before it brings up a virtual machine in virtualbox and blue screens the machine. Are you saying this is not the case? (i.e. the command returns Disabled, but some how it's running?)

Thanks!

@Quix0r
Copy link

Quix0r commented Jul 17, 2018

Conflicts found, can you please fix them? Is still crashing with version 2.1.1 (docker installed, vagrant up gives BSOD).

@chrisroberts chrisroberts modified the milestones: 2.1.3, 2.1.4 Jul 30, 2018
@briancain
Copy link
Member

Hi there, this check was improved via a997a27 which includes the ability to check on Windows Sever. I'm going to close this pull request now. Thanks!

@briancain briancain closed this Aug 30, 2018
@Quix0r
Copy link

Quix0r commented Oct 1, 2018

Nice work.

@ghost
Copy link

ghost commented Mar 29, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants