Open yanhaiqin518 opened 2 years ago
through powershell excute this command is no problem: PS C:\WINDOWS\system32> wsl -l -v NAME STATE VERSION
我也是这个问题,我写了个bash script来自动更新,试试? see: iamqiz/bash-wsl2-host: bash script to Automatically update your Windows hosts file with the WSL2 VM IP address https://github.com/iamqiz/bash-wsl2-host
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
see: berndgz/wsl2hosts: Bash script to automatically update your Windows hosts file with the WSL2 VM IP address and name. https://github.com/berndgz/wsl2hosts
Same here :/
Right now I'm able to make it working by calling wsl2host.exe run
right after WSL start. Latest development version is needed: https://github.com/shayne/go-wsl2-host/releases/tag/latest
I wanted to automate the running of wslhost.exe run
, so I made a powershell script which is run by ~/.zshenv
or ~/.bash_profile
(so not that often) which makes a Windows Event Log. Then made a Scheduled Task which runs wslhost.exe run
when that event occurs.
Everything works fine, but a terminal window opens up briefly while wsl2hosts
runs, which is annoying. I can't hide it by running as the SYSTEM account as it doesn't work ☹️
The systemctl script run upon network interface changes after ip address change. Bash profile only triggers only after you login via ssh/telnet. So systemctl is the best choice.
@bayard Yes, using a systemd service is a much better idea, but I still cannot use cmdow to hide the go-wsl2-host
window without run
being the default action, as it won't take arguments.
It does seem to do it by default when double-clicking the executable, so if anybody could fix that, that would be cool.
@bayard I am using your solution now, which works nicely. The only small downside is having to make the hosts file user writable. I have made a PR for a couple of minor changes. Cheers.
Windows Log -> Application: failed to get infos: wsl list all failed: wsl -l -v failed: exit status 1