wikiped/Wsl-IpHandler

Bash scripts cannot be found when module is installed on a network share (i.e. Error: install-wsl-iphandler.sh: No such file or directory)

Closed this issue · 10 comments

Sorry for posting all these issues. But running the new version 0.11.5 I once again get an error that the install-wsl-iphandler.sh is not found. Have verified that it exists in the correct folder..

Install-WslIpHandler -WslInstanceName Ubuntu-20.04 -GatewayIpAddress 172.26.0.1 -WslInstanceIpAddress 172.26.0.2 -UseScheduledTaskOnUserLogOn -DontModifyPsProfile -Verbose
PowerShell installing WSL-IpHandler to Ubuntu-20.04...
VERBOSE: Hyper-V VM Adapter 'WSL' already exists.
VERBOSE: Hyper-V VM Adapter 'WSL' already has required Gateway: '172.26.0.1' and PrefixLength: '24'!
VERBOSE: Setting Static IP Address: 172.26.0.2 for Ubuntu-20.04.
VERBOSE: Registering WSL-IpHandler scheduled task...
VERBOSE: Scheduled Task to register: \WSL-IpHandler\WSL-IpHandlerTask
VERBOSE: Task command: 'C:\Program Files\PowerShell\7\pwsh.exe'
VERBOSE: Task command arguments: "-NoLogo -NoProfile -NonInteractive -WindowStyle Hidden -Command `"Import-Module '\\<SERVER>\<USER>\PowerShell\Modules\Wsl-IpHandler\WSL-IpHandler.psd1'; Set-WslNetworkAdapter -Wait -Timeout:30 -Toast -Duration:5`""
VERBOSE: Running Bash WSL Install script Microsoft.PowerShell.Core\FileSystem::\\<SERVER>\<USER>\PowerShell\Modules\Wsl-IpHandler\Scripts\Bash\install-wsl-iphandler.sh
[sudo] password for <USER>:
bash: Microsoft.PowerShell.Core/FileSystem::/<SERVER>/<USER>/PowerShell/Modules/Wsl-IpHandler/Scripts/Bash/install-wsl-iphandler.sh: No such file or directory

VERBOSE: Installed Bash scripts.
VERBOSE: Terminating running instances of Ubuntu-20.04 ...
VERBOSE: Testing Activation of WSL IP Handler on Ubuntu-20.04 ...
VERBOSE: Testing Ping from WSL instance Ubuntu-20.04: "ping -c1 windows 2>&1" ...
VERBOSE: Hyper-V VM Adapter 'WSL' already exists.
VERBOSE: Hyper-V VM Adapter 'WSL' already has required Gateway: '172.26.0.1' and PrefixLength: '24'!
VERBOSE: vEthernet (WSL) Network Connection Setup succeeded after [0] seconds.
VERBOSE: Ping from WSL Instance Ubuntu-20.04 failed:
ping: windows: Temporary failure in name resolution
VERBOSE: Testing Ping from Windows to WSL instance Ubuntu-20.04 ...
VERBOSE: Ping from Windows to WSL instance Ubuntu-20.04 failed:
Ping request could not find host Ubuntu-20.04. Please check the name and try again.
VERBOSE: Test-WslInstallation on Ubuntu-20.04 Failed!
PowerShell finished installation of WSL-IpHandler to Ubuntu-20.04 with Errors:
Pinging windows from Ubuntu-20.04 failed:
ping: windows: Temporary failure in name resolution

Running with debug-option enabled I think this is the command that fails..

DEBUG: Install-WslBashScripts [439]: Invoking: wsl.exe -d Ubuntu-20.04 sudo -E env '"PATH=$PATH"' DEBUG=1 VERBOSE=1 
bash  $(wslpath "Microsoft.PowerShell.Core\FileSystem::\\<SERVER>\<USER>\PowerShell\Modules\Wsl-IpHandler\Scripts\Bash\install-wsl-iphandler.sh") 
"Microsoft.PowerShell.Core\FileSystem::\\<SERVER>\<USER>\PowerShell\Modules\Wsl-IpHandler\Scripts\Bash\wsl-iphandler.sh" 
/usr/local/bin "Microsoft.PowerShell.Core\FileSystem::\\<SERVER>\<USER>\PowerShell\Modules\Wsl-IpHandler\Scripts\Powershell\WSL-WinHostsEdit.ps1" 
windows Ubuntu-20.04 172.26.0.2

At the end or running the script the following errors are presented:

PowerShell finished installation of WSL-IpHandler to Ubuntu-20.04 with Errors:
DEBUG: Install-WslIpHandler [234]: ScriptStackTrace: 
at Test-WslInstallation, \\<SERVER>\<USER>\PowerShell\Modules\Wsl-IpHandler\WSL-IpHandler.psm1: line 1576
at Install-WslIpHandler, \\<SERVER>\<USER>\PowerShell\Modules\Wsl-IpHandler\WSL-IpHandler.psm1: line 230
at <ScriptBlock>, <No file>: line 1

Been thinking.. Could my problems come from the fact that my windows user-directory is on a network share, so the $bashInstallScriptWslPath, $BashAutorunScriptSource and $WinHostsEditScript all point to this? And this network share is probably not mounted in the wsl instance? If this is the case - what would be the easiest way to solve the problem?

Your thinking is going in the right direction. Network shares are not supported by WSL according to this post. So I don't see what this module can do, except, may be, for a warning in case network share is being used.

Would it solve the problem if I placed the WSL-IPHandler module outside of my user home-directory but on a local hard drive and then importing it to PowerShell from there? Something like this:

Import-Module -Name c:\ps-test\modules\WSL-IpHandler -Verbose

You can install the module in any location on a local drive and the module will work just as well. It's just to manually Import-Module you need to provide full path to module's folder (as you did: Import-Module 'c:\ps tests\modules\WSL-IpHandler') and if the path contains spaces it should be quoted.

If you don't use parameter -DontModifyPsProfile of Install-WslIpHandler command you will have this import done for you automatically in every PS session.

Thanks for the support. Now the Install-WslIpHandler runs wo errors up to the final verification. When verifying I can ping my WSL host from Windows. But trying to ping "windows" from WSL does not work, and also no luck when trying to ping the IP I assigned to the windows host. From the WSL client there is no internet connectivity at all it seems - so running things like "apt update" and the like does not work..

Sadly I know little about setting up networking on linux - some info from my WSL below.

Can you help me locate what is wrong?

On WSL contents of resolv.conf is like this:

# [network]
# generateResolvConf = false
nameserver 172.26.0.1

Output of "route -e":

Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         windows         0.0.0.0         UG        0 0          0 eth0
windows         0.0.0.0         255.255.255.255 UH        0 0          0 eth0

Output of "ip route"

default via 172.26.0.1 dev eth0
172.26.0.1 dev eth0 scope link

Ouput of "ifconfig":

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet6 fe80::215:5dff:fe45:944b  prefixlen 64  scopeid 0x20<link>
        ether 00:15:5d:45:94:4b  txqueuelen 1000  (Ethernet)
        RX packets 3701  bytes 460752 (460.7 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 76  bytes 6416 (6.4 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0:wsliphndlr: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.26.0.2  netmask 255.255.255.255  broadcast 0.0.0.0
        ether 00:15:5d:45:94:4b  txqueuelen 1000  (Ethernet)

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 14  bytes 1176 (1.1 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 14  bytes 1176 (1.1 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I tried basically everything but can't get networking from the linux-client in WSL2 to work.

I cannot justify spending more time on this so I admit I'm defeated and revert back to WSL1 (which for me works right out of the box). And eagerly await an update from Microsoft on how networking in WSL2 is set up.

Closing this issue.

In version - 0.12.0 there is now a safeguard to make sure a warning is shown to the user when the module is installed on a network share.

Regarding you ping windows problem:

  1. Do not edit resolv.conf manually - let windows to handle this. This module does not touch resolv.conf in any way.

  2. For resolv.conf and the module to operate normally /etc/wsl.conf must be either empty (i.e. to have default values) or have the following lines not set to false:
    [automount]
    enabled = true
    [interop]
    appendWindowsPath = true
    [network]
    generateResolvConf = true

  3. In version 0.12.0 there is Get-WslStatus command. Which retrieves information from both WSL on Windows and on Linux. Run it to see the status of configuration and scripts availability on Linux side. Post the results here if want me to look into this. Otherwise you can try the next point.

  4. Try ping 172.26.0.1 instead of ping windows. If this works - the problem most likely in hosts file not being updated (if this is the case - it is good reason to raise an issue). If this doesn't work see next point.

  5. Try Uninstall-WslIpHandler Ubuntu-20.04 followed be Remove-WslNetworkAdapter. Wait for about 10 seconds for the adapter changes to take effect. Then wsl.exe -d Ubuntu-20.04 and try pinging windows IP address, which can be seen in resolv.conf (by default linux subsystem has no awareness of windows-host-name). If this works then there is an issue either with the way the module is being used or the way it handles bash scripts.

So after running WSL1 for a while i switched back to WSL2, reinstalled Wsl-IpHandler and tried to do some troubleshooting along the lines you suggested..

  1. I have not edited resolf.conf manually
  2. My /etc/wsl.conf looks like this
XXX@YYY:/mnt/c/Users/XXX cat /etc/wsl.conf
[network]
static_ip = 172.26.0.2
wsl_host = Ubuntu-20.04
windows_host = windows
generateResolvConf = true

[automount]
enabled = true
options = "metadata"
mountFsTab = false
  1. The results of Get-WslStatus looks like this
PS C:\Users\XXX> Get-WslStatus

WslInstances          : Ubuntu-20.04
StaticIp              : @{Ubuntu-20.04=172.26.0.2}
WslSubnet             : 172.26.0.1/24
WslSwapEnabled        : True
WslSwapFile           : %USERPROFILE%\AppData\Local\Temp\swap.vhdx
WslSwapFileCompressed : False
ModuleOnPath          : False
ModuleOnNetworkShare  : False
ProfileModified       : \\XXX\YYY\PowerShell\profile.ps1
ScheduledTaskExists   : False
  1. Pinging 172.26.0.1 makes no change from ping windows
  2. Tried uninstalling and removing the network adapter. After that I get an error message when running wsl.exe -d Ubuntu-20.04 that says something loosely translated as "Element not found"..

The Element not found error is most likely an indication that wsl.exe is having trouble starting the instance.

One problem that I am aware of when seeing the message like this is linked to the swap that is enabled for the instance. But this is not definite.

You can read about this in swap section of the README.

Can you also post here the output from Get-WslInstanceStatus Ubuntu-20.04?