shayne / go-wsl2-host

Automatically update your Windows hosts file with the WSL2 VM IP address
1.65k stars 140 forks source link

Upgrading to latest WSL (Windows Store version) stops the GO-WSL2-HOST working #67

Open jaycangel opened 2 years ago

jaycangel commented 2 years ago

WSL has recently moved to a "windows store" application. I upgraded by running wsl.exe --update. My wsl ubuntu server works fine buut go-wsl2-host no longer detects the change in IP and updates host file.

I'm not sure what's changed in the underlying architecture anymore but sadly the service doesn't work anymore. I'm on Windows 11 - latest everything

jaycangel commented 2 years ago

For more information on what i mean by Windows Store Application here is the release article - https://devblogs.microsoft.com/commandline/a-preview-of-wsl-in-the-microsoft-store-is-now-available/

mrebello commented 2 years ago

After update to "ubuntu" (instead of ubuntu2004) and install docker: C:\xxx>wsl2host debug

wsl2host.info(1): starting wsl2host service panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x0 addr=0x8 pc=0x50c352]

goroutine 1 [running]: github.com/shayne/go-wsl2-host/cmd/wsl2host/pkg/service.Run(0x5812a0, 0xc000058570, 0x2, 0x0) /workspaces/go-wsl2-host/cmd/wsl2host/pkg/service/service.go:92 +0x742 github.com/shayne/go-wsl2-host/cmd/wsl2host/internal.(*windowserver).Execute(0x687be0, 0xc000058590, 0x1, 0x1, 0xc00006a120, 0xc00006a180, 0xc00000a560) /workspaces/go-wsl2-host/cmd/wsl2host/internal/service.go:33 +0x523 golang.org/x/sys/windows/svc/debug.Run(0x554639, 0x8, 0x57fc20, 0x687be0, 0x0, 0x0) /go/pkg/mod/golang.org/x/sys@v0.0.0-20190626221950-04f50cda93cb/windows/svc/debug/service.go:40 +0x153 github.com/shayne/go-wsl2-host/cmd/wsl2host/internal.RunService(0x554639, 0x8, 0xc000010001) /workspaces/go-wsl2-host/cmd/wsl2host/internal/service.go:81 +0x1bf main.main() /workspaces/go-wsl2-host/cmd/wsl2host/main.go:42 +0x384

Ars3n3-Lupin commented 1 year ago

WSL has recently moved to a "windows store" application. I upgraded by running wsl.exe --update. My wsl ubuntu server works fine buut go-wsl2-host no longer detects the change in IP and updates host file.

I'm not sure what's changed in the underlying architecture anymore but sadly the service doesn't work anymore. I'm on Windows 11 - latest everything

I didn't find if you solwed this issue but I have found the same problem after upgrading to windows 11 last version.

Resolving is so easy.

Navigate to hosts file C:\Windows\System32\drivers\etc\hosts -> right click on hosts file -> untick (read-only) if it was not ticked -> go to the security card and change user privilages to the same as admin has

Here is how you can do it https://techcult.com/fix-access-denied-when-editing-hosts-file/ it is marked as method 2 and 3

The next step is .\wsl2host.exe stop .\wsl2host.exe remove .\wsl2host.exe install

that's it . Maybe it helps to other users ;)

Ars3n3-Lupin commented 1 year ago

Hi

After the last Windows 11 update => latest version 22H2 (OS build 22621.608) I can only run wsl2host.exe in debug mode.

.\wsl2host.exe install => it succeeded. I logged in as local user. I checked windows services and it's running good until I tried ping ubuntu2004.wsl. Ping is not working. IP address in hosts file is not changed after restarting system. But windows services running properly. Auto-start and logging in works good.

I tried remove wsl2host.exe and install it again and again but it doesn't help.

Everything I can do is run wsl2host.exe in debug mode. This starts wsl2host.exe properly.

I looked into Event viewer in windows and I have found one repeated wsl2host error. "failed to get infos: wsl list all failed: wsl -l -v failed: exit status 1" But after typing wsl -l -v in powershel , it shows me results of running distros properly.

Is there a way how to solve this problem to run wsl2host not just in debug mode as I run before?

bayard commented 1 year ago

Wsl2host is broken in latest update of windows 11 (Only work in debug mode, service mode result in "wsl -l -v error" and cannot obtain ip address of wsl.). I wrote a script in linux to complete the job, see: https://github.com/bayard/WSL2_UPDATE_HOSTS

Kwaadpepper commented 1 year ago

Are there any instructions on how to configure this properly as a workaround for now ? I mean for using wsl2host

gdragon-git commented 1 year ago

Would also love a fix