diff --git a/drivers/virtualbox/virtualbox.go b/drivers/virtualbox/virtualbox.go index b838424bb2..25e5ad3826 100644 --- a/drivers/virtualbox/virtualbox.go +++ b/drivers/virtualbox/virtualbox.go @@ -187,24 +187,6 @@ func (d *Driver) PreCreateCheck() error { return d.vbm() } -// IsVTXDisabled checks if VT-X is disabled in the BIOS. If it is, the vm will fail to start. -// If we can't be sure it is disabled, we carry on and will check the vm logs after it's started. -func (d *Driver) IsVTXDisabled() bool { - if runtime.GOOS == "windows" { - output, err := cmdOutput("wmic", "cpu", "get", "VirtualizationFirmwareEnabled") - if err != nil { - log.Debugf("Couldn't check that VT-X/AMD-v is enabled. Will check that the vm is properly created: %v", err) - return false - } - - disabled := strings.Contains(output, "FALSE") - return disabled - } - - // TODO: linux and OSX - return false -} - // cmdOutput runs a shell command and returns its output. func cmdOutput(name string, args ...string) (string, error) { cmd := exec.Command(name, args...) diff --git a/drivers/virtualbox/virtualbox_darwin.go b/drivers/virtualbox/virtualbox_darwin.go new file mode 100644 index 0000000000..e044e1e7ef --- /dev/null +++ b/drivers/virtualbox/virtualbox_darwin.go @@ -0,0 +1,22 @@ +package virtualbox + +import ( + "strings" + "syscall" + + "github.com/docker/machine/libmachine/log" +) + +// IsVTXDisabled checks if VT-X is disabled in the BIOS. If it is, the vm will fail to start. +// If we can't be sure it is disabled, we carry on and will check the vm logs after it's started. +func (d *Driver) IsVTXDisabled() bool { + errmsg := "Couldn't check that VT-X/AMD-v is enabled. Will check that the vm is properly created: %v" + features, err := syscall.Sysctl("machdep.cpu.features") + if err != nil { + log.Debugf(errmsg, err) + return false + } + + disabled := !strings.Contains(features, "VMX") + return disabled +} diff --git a/drivers/virtualbox/virtualbox_linux.go b/drivers/virtualbox/virtualbox_linux.go new file mode 100644 index 0000000000..f5892d6fb4 --- /dev/null +++ b/drivers/virtualbox/virtualbox_linux.go @@ -0,0 +1,7 @@ +package virtualbox + +// IsVTXDisabled checks if VT-X is disabled in the BIOS. If it is, the vm will fail to start. +// If we can't be sure it is disabled, we carry on and will check the vm logs after it's started. +func (d *Driver) IsVTXDisabled() bool { + return false +} diff --git a/drivers/virtualbox/virtualbox_windows.go b/drivers/virtualbox/virtualbox_windows.go new file mode 100644 index 0000000000..33da8b470d --- /dev/null +++ b/drivers/virtualbox/virtualbox_windows.go @@ -0,0 +1,21 @@ +package virtualbox + +import ( + "strings" + + "github.com/docker/machine/libmachine/log" +) + +// IsVTXDisabled checks if VT-X is disabled in the BIOS. If it is, the vm will fail to start. +// If we can't be sure it is disabled, we carry on and will check the vm logs after it's started. +func (d *Driver) IsVTXDisabled() bool { + errmsg := "Couldn't check that VT-X/AMD-v is enabled. Will check that the vm is properly created: %v" + output, err := cmdOutput("wmic", "cpu", "get", "VirtualizationFirmwareEnabled") + if err != nil { + log.Debugf(errmsg, err) + return false + } + + disabled := strings.Contains(output, "FALSE") + return disabled +}