Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After upgrading from WSL1 to WSL2, message of the day still displays "Running WSL version 1" #714

Closed
LBates2000 opened this issue Oct 9, 2021 · 13 comments
Assignees
Labels
Bug This is a problem.

Comments

@LBates2000
Copy link

LBates2000 commented Oct 9, 2021

  1. Upgrade WLinux from WSL1 to WSL2
  2. wsl.exe --terminate WLinux
  3. wsl.exe --shutdown
  4. Restart WLinux
  5. Run sudo run-parts /etc/update-motd.d/ to redisplay the message of the day:
Welcome to Pengwin (21.9.0), Based on debian 11 (bullseye)
Linux REDACTED 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64

 * Home:           https://github.com/whitewaterfoundry/Pengwin
 * Support:        https://github.com/WhitewaterFoundry/Pengwin/issues

 Pengwin includes 'Pengwin Setup,' which allow new Pengwin users to get started on Linux immediately
 To execute, run: pengwin-setup
 To check for updates, run: pengwin-setup update

 Environment variables:
  DISPLAY               :0
  WSL_DISTRO_NAME       WLinux

 Network
  IPv4 for lo                   127.0.0.1
  IPv4 for eth0                 172.29.189.147

 Windows Home Location:  /root/winhome
 The Windows C: drive is mounted at: /c/
 To open the current folder with Windows Explorer, run: wslview .

 Running WSL version 1 <--------
 
OS: Debian 11 bullseye(on the Windows Subsystem for Linux)
Kernel: x86_64 Linux   5.10.60.1-microsoft-standard-WSL2
Uptime: 22m
Packages: 2566
Shell: bash 5.1.4
Resolution: 3840x1080
WM: Weston WM
GTK Theme: Clearlooks [GTK2/3]
Icon Theme: nuoveXT2
Font: Sans 10
Disk: 15T / 24T (62%)
CPU: Intel Core i7-6700K @ 8x 4.008GHz
GPU: NVIDIA GeForce GTX 1080
RAM: 561MiB / 15938MiB
  • Message of the day still displays "Running WSL version 1"
  • echo ${WSL_INTEROP} shows /run/WSL/2983_interop
  • echo ${WSL2} shows that the environment variable is still unset

I could manually set the WSL2 environment variable, but I'm not sure what it should be set to:

  # WSL2 Environment variable meaning:
  # WSL2=0: WSL1
  # WSL2=1: WSL2 (Type 1)
  # WSL2=2: WSL2 (Type 2)
  # WSL2=3: WSL2 (Type 3)

I'm also concerned that other parts of my system configuration may not be set correctly.

PENGWIN_VERSION="21.9.0"

WSL Version: 2
Locale: en_US
Release Install Date: Tue Jun 29 12:26:44 PDT 2021
Branch: co_release
Build: 22000
Full Build: 22000.1.amd64fre.co_release.210604-1628
Display Scaling: 1
Windows Theme: dark
Windows Uptime: 1d 14h 44m
WSL Uptime: 0d 5h 50m
WSL Release: Pengwin
WSL Kernel: Linux 5.10.60.1-microsoft-standard-WSL2
Packages Count: 2566

@LBates2000 LBates2000 added the Bug This is a problem. label Oct 9, 2021
@crramirez
Copy link
Collaborator

Hello @LBates2000 ,

Thanks for reporting this. It should set the WSL2 variable, so 00-pengwin.sh is failing for any reason. We will take a look. Manually setting the WSL2 variable to any value should work.

Regards,
Carlos

@crramirez crramirez self-assigned this Oct 9, 2021
@crramirez
Copy link
Collaborator

Hello @LBates2000,

The problem is that the WSL2 variable is not transferred through sudo. I mean.

sudo run-parts /etc/update-motd.d/ Will show you Running WSL version 1

but

run-parts /etc/update-motd.d/ Will show you Running WSL version 2

Regards,
Carlos

@LBates2000
Copy link
Author

This is the MOTD at startup:

Welcome to Pengwin (21.10.1), Based on debian 11 (bullseye)
Linux ENDEAVOR 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64

 * Home:           https://github.com/whitewaterfoundry/Pengwin
 * Support:        https://github.com/WhitewaterFoundry/Pengwin/issues

 Pengwin includes 'Pengwin Setup,' which allow new Pengwin users to get started on Linux immediately
 To execute, run: pengwin-setup
 To check for updates, run: pengwin-setup update

 Environment variables:
  DISPLAY               :0
  WSL_DISTRO_NAME       WLinux
  WAYLAND_DISPLAY       wayland-0
  PULSE_SERVER          /mnt/wslg/PulseServer

 Network
  IPv4 for lo                   127.0.0.1
  IPv4 for eth0                 172.24.144.18

 Windows Home Location:  /home/lbates/winhome
 The Windows C: drive is mounted at: /c/
 To open the current folder with Windows Explorer, run: wslview .

 Running WSL version 1

And this is running run-parts /etc/update-motd.d/ without sudo:

$ run-parts /etc/update-motd.d/

Welcome to Pengwin (21.10.1), Based on debian 11 (bullseye)
Linux ENDEAVOR 5.10.60.1-microsoft-standard-WSL2 #1 SMP Wed Aug 25 23:20:18 UTC 2021 x86_64

 * Home:           https://github.com/whitewaterfoundry/Pengwin
 * Support:        https://github.com/WhitewaterFoundry/Pengwin/issues

 Pengwin includes 'Pengwin Setup,' which allow new Pengwin users to get started on Linux immediately
 To execute, run: pengwin-setup
 To check for updates, run: pengwin-setup update

 Environment variables:
  DISPLAY               :0
  WSL_DISTRO_NAME       WLinux
  WAYLAND_DISPLAY       wayland-0
  PULSE_SERVER          /mnt/wslg/PulseServer

 Network
  IPv4 for lo                   127.0.0.1
  IPv4 for eth0                 172.24.144.18

 Windows Home Location:  /home/lbates/winhome
 The Windows C: drive is mounted at: /c/
 To open the current folder with Windows Explorer, run: wslview .

 Running WSL version 1

@LBates2000
Copy link
Author

LBates2000 commented Oct 10, 2021

It looks as though /etc/profile.d/00-pengwin.sh should be setting WSL2=3

lbates@ENDEAVOR:~ $ bash -x -v /etc/profile.d/00-pengwin.sh
# System-wide .bashrc file for interactive bash(1) shells.

# Start or enter a PID namespace in WSL2
#source /usr/sbin/start-systemd-namespace

# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.

# If not running interactively, don't do anything
[ -z "$PS1" ] && return
+ '[' -z '' ']'
+ return
#!/bin/sh

# Only the default WSL user should run this script
if ! (id -Gn | grep -c "adm.*sudo\|sudo.*adm" >/dev/null); then
  return
fi
+ id -Gn
+ grep -c 'adm.*sudo\|sudo.*adm'
+ return
/etc/profile.d/00-pengwin.sh: line 5: return: can only `return' from a function or sourced script

setup_display() {

  if [ -n "${XRDP_SESSION}" ]; then
    return
  fi

  # WSL2 Environment variable meaning:
  # WSL2=0: WSL1
  # WSL2=1: WSL2 (Type 1)
  # WSL2=2: WSL2 (Type 2)
  # WSL2=3: WSL2 (Type 3)
  if [ -n "${WSL_INTEROP}" ]; then

    if [ -n "${DISPLAY}" ]; then
      # check if the type is changed
      sudo /usr/local/bin/wsl_change_checker 3 "WSL2" "${DISPLAY}"
      sudo /usr/local/bin/wsl2_ip_checker "$(echo "$DISPLAY" | cut -d : -f 1)"
      #Export an enviroment variable for helping other processes
      export WSL2=3

      return
    fi

    # enable external x display for WSL 2
    ipconfig_exec=$(wslpath "C:\\Windows\\System32\\ipconfig.exe")
    if (command -v ipconfig.exe >/dev/null 2>&1); then
      ipconfig_exec=$(command -v ipconfig.exe)
    fi

    wsl2_d_tmp="$(eval "$ipconfig_exec 2> /dev/null" | grep -n -m 1 "Default Gateway.*: [0-9a-z]" | cut -d : -f 1)"

    if [ -n "${wsl2_d_tmp}" ]; then

      wsl2_d_tmp="$(eval "$ipconfig_exec" | sed "$((wsl2_d_tmp - 4))"','"$((wsl2_d_tmp + 0))"'!d' | grep IPv4 | cut -d : -f 2 | sed -e "s|\s||g" -e "s|\r||g")"
      export DISPLAY=${wsl2_d_tmp}:0

      # check if the type is changed
      sudo /usr/local/bin/wsl_change_checker 2 "WSL2" "${wsl2_d_tmp}:0\.0"
      sudo /usr/local/bin/wsl2_ip_checker "$wsl2_d_tmp"
      #Export an enviroment variable for helping other processes
      export WSL2=2

    else
      wsl2_d_tmp="$(grep </etc/resolv.conf nameserver | awk '{print $2}')"
      export DISPLAY=${wsl2_d_tmp}:0

      # check if we have wsl.exe in path
      sudo /usr/local/bin/wsl_change_checker 1 "WSL2" "$DISPLAY"
      sudo /usr/local/bin/wsl2_ip_checker "$wsl2_d_tmp"
      #Export an enviroment variable for helping other processes
      export WSL2=1
    fi

    unset ipconfig_exec
    unset wsl2_d_tmp

  else

    # enable external x display for WSL 1
    export DISPLAY=localhost:0

    # check if we have wsl.exe in path
    sudo /usr/local/bin/wsl_change_checker 0 "WSL1" "localhost:0"

    # Export an enviroment variable for helping other processes
    unset WSL2

  fi
}

setup_display
+ setup_display
+ '[' -n '' ']'
+ '[' -n /run/WSL/3290_interop ']'
+ '[' -n :0 ']'
+ sudo /usr/local/bin/wsl_change_checker 3 WSL2 :0
++ echo :0
++ cut -d : -f 1
+ sudo /usr/local/bin/wsl2_ip_checker ''
+ export WSL2=3
+ WSL2=3
+ return

# enable external libgl if mesa is not installed
if (command -v glxinfo >/dev/null 2>&1); then
  unset LIBGL_ALWAYS_INDIRECT
  sudo /usr/local/bin/libgl-change-checker 0
else
  export LIBGL_ALWAYS_INDIRECT=1
  sudo /usr/local/bin/libgl-change-checker 1
fi
+ command -v glxinfo
+ unset LIBGL_ALWAYS_INDIRECT
+ sudo /usr/local/bin/libgl-change-checker 0

# speed up some GUI apps like gedit
export NO_AT_BRIDGE=1
+ export NO_AT_BRIDGE=1
+ NO_AT_BRIDGE=1

# Fix 'clear' scrolling issues
alias clear='clear -x'
+ alias 'clear=clear -x'

# Custom aliases
alias ll='ls -al'
+ alias 'll=ls -al'
alias winget='powershell.exe winget'
+ alias 'winget=powershell.exe winget'

# Check if we have Windows Path
if (command -v cmd.exe >/dev/null); then

  # Execute on user's shell first-run
  if [ ! -f "${HOME}/.firstrun" ]; then
    echo "Welcome to Pengwin. Type 'pengwin-setup' to run the setup tool. You will only see this message on the first run."
    touch "${HOME}/.firstrun"
  fi

  # shellcheck disable=SC1003
  if (! wslpath 'C:\' >/dev/null 2>&1); then
    # shellcheck disable=SC2262
    alias wslpath=legacy_wslupath
  fi

  # Create a symbolic link to the windows home

  # Here have a issue: %HOMEDRIVE% might be using a custom set location
  # moving cmd to where Windows is installed might help: %SYSTEMDRIVE%
  wHomeWinPath=$(cmd.exe /c 'cd %SYSTEMDRIVE%\ && echo %HOMEDRIVE%%HOMEPATH%' 2>/dev/null | tr -d '\r')

  if [ ${#wHomeWinPath} -le 3 ]; then #wHomeWinPath contains something like H:\
    wHomeWinPath=$(cmd.exe /c 'cd %SYSTEMDRIVE%\ && echo %USERPROFILE%' 2>/dev/null | tr -d '\r')
  fi

  # shellcheck disable=SC2155
  export WIN_HOME=$(wslpath -u "${wHomeWinPath}")

  win_home_lnk=${HOME}/winhome
  if [ ! -e "${win_home_lnk}" ]; then
    ln -s -f "${WIN_HOME}" "${win_home_lnk}" >/dev/null 2>&1
  fi

  unset win_home_lnk
fi
+ command -v cmd.exe
+ '[' '!' -f /home/lbates/.firstrun ']'
+ wslpath 'C:\'
++ cmd.exe /c 'cd %SYSTEMDRIVE%\ && echo %HOMEDRIVE%%HOMEPATH%'
++ tr -d '\r'
+ wHomeWinPath='C:\Users\lbates'
+ '[' 15 -le 3 ']'
++ wslpath -u 'C:\Users\lbates'
+ export WIN_HOME=/c/Users/lbates
+ WIN_HOME=/c/Users/lbates
+ win_home_lnk=/home/lbates/winhome
+ '[' '!' -e /home/lbates/winhome ']'
+ unset win_home_lnk

but I still do not see the environment variable being set:

lbates@ENDEAVOR:~ $ env | grep WSL2
lbates@ENDEAVOR:~ $ echo ${WSL2}

@crramirez
Copy link
Collaborator

You are right. I'll recheck with Windows 11

@laurinkeithdavis
Copy link

I have this issue on Windows 10 Pro (21H1):

image

image

@laurinkeithdavis
Copy link

I did this:

wsl --unregister WLinux

Launched Pengwin, now it's working. Weird.

@crramirez
Copy link
Collaborator

@LBates2000 could you please run this command and send me the result?

id -Gn | grep -c "adm.*sudo\|sudo.*adm"`

@LBates2000
Copy link
Author

@crramirez

lbates@ENDEAVOR:~ $ id -Gn | grep -c "adm.*sudo\|sudo.*adm"
0

@crramirez
Copy link
Collaborator

Did you remove your user from the sudo group?

@laurinkeithdavis
Copy link

Did you remove your user from the sudo group?

I did not, but I was having #715 before this occurred, which went away with a restart of Windows.

@LBates2000
Copy link
Author

LBates2000 commented Oct 22, 2021

@crramirez No, I'm in the sudo group:

lbates@ENDEAVOR:~ $ grep '^sudo:.*$' /etc/group | cut -d: -f4
lbates

lbates@ENDEAVOR:~ $ cat /etc/group | grep lbates
sudo:x:27:lbates
kvm:x:106:lbates
lbates:x:1000:
docker:x:1001:lbates
libvirtd:x:1002:lbates

lbates@ENDEAVOR:~ $ sudo -l -U lbates
Matching Defaults entries for lbates on ENDEAVOR:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
    env_keep+=WSLPATH, env_keep+=WSLENV, env_keep+=WSL_INTEROP, env_keep+=WSL_DISTRO_NAME,
    env_keep+=PRE_NAMESPACE_PATH, env_keep+=PRE_NAMESPACE_PWD

User lbates may run the following commands on ENDEAVOR:
    (ALL : ALL) ALL
    (root) NOPASSWD: /usr/bin/create-mnt-c-link
    (root) NOPASSWD: /usr/bin/create-mnt-c-link
    (root) NOPASSWD: /usr/bin/docker-relay
    (root) NOPASSWD: /usr/bin/mount-proc
    (root) NOPASSWD: /usr/bin/mount-proc
    (root) NOPASSWD: /usr/bin/mount-proc
    (root) NOPASSWD: /usr/local/bin/wsl_change_checker
    (root) NOPASSWD: /usr/local/bin/wsl2_ip_checker
    (root) NOPASSWD: /usr/local/bin/libgl-change-checker
    (root) NOPASSWD: /bin/bash /etc/rc.local
    (root) NOPASSWD: /bin/bash /etc/rc.local
    (root) NOPASSWD: /bin/bash /etc/rc.local
    (root) NOPASSWD: /usr/bin/start-cassandra
    (root) NOPASSWD: /usr/bin/start-cassandra
    (root) NOPASSWD: /usr/bin/start-cassandra
    (root) NOPASSWD: /usr/bin/start-ssh
    (root) NOPASSWD: /usr/bin/start-ssh
    (root) NOPASSWD: /usr/bin/start-ssh
    (root) NOPASSWD: /usr/bin/start-ssh
    (root) NOPASSWD: /usr/bin/start-ssh
    (root) NOPASSWD: /usr/bin/start-ssh
    (root) NOPASSWD: /usr/bin/start-ssh
    (root) NOPASSWD: /usr/bin/start-ssh
    (ALL) NOPASSWD: /usr/sbin/enter-systemd-namespace

@crramirez
Copy link
Collaborator

@LBates2000 ok I can conclude that your user is not in the adm group. I can change the script to look for only the sudo group

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This is a problem.
Projects
None yet
Development

No branches or pull requests

3 participants