From 1356ac63b46d0212d06f8e8a0cf03cc2e72a2c75 Mon Sep 17 00:00:00 2001 From: Swastik Baranwal Date: Wed, 2 Dec 2020 19:11:13 +0530 Subject: [PATCH] doctor: detect wsl 1 and wsl 2 separately (#7081) --- cmd/tools/vdoctor.v | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/cmd/tools/vdoctor.v b/cmd/tools/vdoctor.v index 1db57b393a..fec3e80efe 100644 --- a/cmd/tools/vdoctor.v +++ b/cmd/tools/vdoctor.v @@ -50,18 +50,26 @@ fn (mut a App) collect_info() { } // mut os_details := '' + wsl_check := a.cmd({ + command: 'cat /proc/sys/kernel/osrelease' + }) if os_kind == 'linux' { os_details = a.get_linux_os_name() info := a.cpu_info() if 'hypervisor' in info['flags'] { - if 'microsoft' in a.cmd({ - command: 'cat /proc/sys/kernel/osrelease' - }) { - os_details += ' (WSL)' + if 'microsoft' in wsl_check { + // WSL 2 is a Managed VM and Full Linux Kernel + // See https://docs.microsoft.com/en-us/windows/wsl/compare-versions + os_details += ' (WSL 2)' } else { os_details += ' (VM)' } } + // WSL 1 is NOT a Managed VM and Full Linux Kernel + // See https://docs.microsoft.com/en-us/windows/wsl/compare-versions + if 'Microsoft' in wsl_check { + os_details += ' (WSL)' + } // From https://unix.stackexchange.com/a/14346 if a.cmd(command: '[ "$(awk \'\$5=="/" {print \$1}\'