Skip to content

Commit

Permalink
Fix crc-org#2131 Add preflight check for WSL2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gbraad committed May 10, 2021
1 parent b4a2109 commit b08c4c1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/crc/preflight/preflight_checks_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions pkg/crc/preflight/preflight_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

func libvirtPreflightChecks(distro *linux.OsRelease) []Check {
checks := []Check{

{
configKeySuffix: "check-virt-enabled",
checkDescription: "Checking if Virtualization is enabled",
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b08c4c1

Please sign in to comment.