From b419c5d9ca22e075df1930dd1d2ace0f850563c3 Mon Sep 17 00:00:00 2001 From: theodthompson Date: Tue, 29 Mar 2016 13:21:45 -0700 Subject: [PATCH] adding hypervisor check to hyper-v driver Signed-off-by: Theo Thompson --- drivers/virtualbox/virtualbox.go | 2 +- drivers/virtualbox/virtualbox_windows.go | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/virtualbox/virtualbox.go b/drivers/virtualbox/virtualbox.go index 11b261bdce..f74dc19c68 100644 --- a/drivers/virtualbox/virtualbox.go +++ b/drivers/virtualbox/virtualbox.go @@ -36,7 +36,7 @@ const ( var ( ErrUnableToGenerateRandomIP = errors.New("unable to generate random IP") ErrMustEnableVTX = errors.New("This computer doesn't have VT-X/AMD-v enabled. Enabling it in the BIOS is mandatory") - ErrNotCompatibleWithHyperV = errors.New("Hyper-V is installed. VirtualBox won't boot a 64bits VM when Hyper-V is activated. If it's installed but deactivated, you can use --virtualbox-no-vtx-check to try anyways") + ErrNotCompatibleWithHyperV = errors.New("This computer is running Hyper-V. VirtualBox won't boot a 64bits VM when Hyper-V is activated. Either use Hyper-V as a driver, or disable the Hyper-V hypervisor. (To skip this check, use --virtualbox-no-vtx-check)") ErrNetworkAddrCidr = errors.New("host-only cidr must be specified with a host address, not a network address") ErrNetworkAddrCollision = errors.New("host-only cidr conflicts with the network address of a host interface") ) diff --git a/drivers/virtualbox/virtualbox_windows.go b/drivers/virtualbox/virtualbox_windows.go index 493cde46f2..c1ecb6c938 100644 --- a/drivers/virtualbox/virtualbox_windows.go +++ b/drivers/virtualbox/virtualbox_windows.go @@ -95,6 +95,25 @@ func getShareDriveAndName() (string, string) { } func isHyperVInstalled() bool { + // check if hyper-v is installed _, err := exec.LookPath("vmms.exe") - return err == nil + if err != nil { + errmsg := "Hyper-V is not installed." + log.Debugf(errmsg, err) + return false + } + + // check to see if a hypervisor is present. if hyper-v is installed and enabled, + // display an error explaining the incompatibility between virtualbox and hyper-v. + output, err := cmdOutput("wmic", "computersystem", "get", "hypervisorpresent") + + if err != nil { + errmsg := "Could not check to see if Hyper-V is running." + log.Debugf(errmsg, err) + return false + } + + enabled := strings.Contains(output, "TRUE") + return enabled + }