From b08c4c1a93c81ad06f658a17fd71e02489dc1df2 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 | 10 ++++++++++ 2 files changed, 24 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..e86421b433 100644 --- a/pkg/crc/preflight/preflight_linux.go +++ b/pkg/crc/preflight/preflight_linux.go @@ -17,6 +17,7 @@ import ( func libvirtPreflightChecks(distro *linux.OsRelease) []Check { checks := []Check{ + { configKeySuffix: "check-virt-enabled", checkDescription: "Checking if Virtualization is enabled", @@ -114,6 +115,14 @@ var vsockPreflightChecks = Check{ cleanup: removeVsockCrcSettings, } +var wsl2PreflightChecks = Check{ + configKeySuffix: "check-wsl2", + checkDescription: "Checking if running inside WSL2", + check: checkRunningInsideWSL2, + fixDescription: "CodeReady Containers is unsupported using WSL2", + flags: NoFix, +} + const ( vsockUdevSystemRulesPath = "/usr/lib/udev/rules.d/99-crc-vsock.rules" vsockUdevLocalAdminRulesPath = "/etc/udev/rules.d/99-crc-vsock.rules" @@ -220,6 +229,7 @@ func removeVsockCrcSettings() error { func getAllPreflightChecks() []Check { usingSystemdResolved := checkSystemdResolvedIsRunning() checks := getPreflightChecksForDistro(distro(), network.DefaultMode, usingSystemdResolved == nil) + checks = append(checks, wsl2PreflightChecks) checks = append(checks, vsockPreflightChecks) return checks }