From 3cfa040dc0d9fdb8d4ba1a63fbd52803a4c39d0e Mon Sep 17 00:00:00 2001 From: Gerard Braad Date: Mon, 10 May 2021 15:23:06 +0800 Subject: [PATCH] Fix #2131 Add preflight check for WSL2 This check looks at the kernel version string and determines if a Microsoft compiled kernel is used, as is the case with WSL2. This is to prevent a setup that uses Nested Virtualization. --- pkg/crc/preflight/preflight_checks_linux.go | 14 ++++++++++++++ pkg/crc/preflight/preflight_linux.go | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/pkg/crc/preflight/preflight_checks_linux.go b/pkg/crc/preflight/preflight_checks_linux.go index b5c0565cd3..583fe432fd 100644 --- a/pkg/crc/preflight/preflight_checks_linux.go +++ b/pkg/crc/preflight/preflight_checks_linux.go @@ -29,6 +29,20 @@ const ( minSupportedLibvirtVersion = "3.4.0" ) +func checkRunningInsideWSL2() error { + version, err := ioutil.ReadFile("/proc/version") + if err != nil { + return err + } + + if strings.Contains(string(version), "Microsoft") { + logging.Debugf("Running inside WSL2 environment") + return fmt.Errorf("CodeReady Containers is unsupported using WSL2") + } + + return nil +} + func checkVirtualizationEnabled() error { logging.Debug("Checking if the vmx/svm flags are present in /proc/cpuinfo") // Check if the cpu flags vmx or svm is present diff --git a/pkg/crc/preflight/preflight_linux.go b/pkg/crc/preflight/preflight_linux.go index eb8eae595a..781780b324 100644 --- a/pkg/crc/preflight/preflight_linux.go +++ b/pkg/crc/preflight/preflight_linux.go @@ -17,6 +17,13 @@ import ( func libvirtPreflightChecks(distro *linux.OsRelease) []Check { checks := []Check{ + { + configKeySuffix: "check-wsl2", + checkDescription: "Checking if running inside WSL2", + check: checkRunningInsideWSL2, + fixDescription: "CodeReady Containers is unsupported using WSL2", + flags: NoFix, + }, { configKeySuffix: "check-virt-enabled", checkDescription: "Checking if Virtualization is enabled",