暗黑模式
WSL
文章WSL
Install
- PowserShell
wsl --install --no-distribution
- Microsoft Store 安装 Ubuntu24
WSL 打不开
现象:
- WSL 打不开,没有反应
- 资源管理器的主文件夹打不开
bash
netsh winsock reset
1
然后重启电脑。
WSL 设置默认分发版本
bash
wsl -l
Ubuntu-20.04(默认)
Ubuntu-22.04
wsl --set-default Ubuntu-22.04
wsl -s Ubuntu-22.04
1
2
3
4
5
2
3
4
5
WSL 卸载某个分发版本
bash
wsl -l
Ubuntu-20.04
Ubuntu-22.04(默认)
wsl --unregister Ubuntu-20.04 # 注意备份
1
2
3
4
2
3
4
LAN局域网访问WSL
Mirrored mode networking
使用 netsh
bash
# 管理员权限运行 PowerShell
netsh interface portproxy add v4tov4 listenport=3000 listenaddress=0.0.0.0 connectport=3000 connectaddress=(wsl hostname -I)
netsh interface portproxy reset # 删除所有映射
1
2
3
2
3
listenport=3000
宿主机(Windows)监听端口listenaddress=0.0.0.0
宿主机监听IP范围,0.0.0.0 表示搜索 IPV4connectport=3000
WSL要暴露出去的端口connectaddress=(wsl hostname -I)
WSL地址(例如 172.25.93.204),wsl hostname -I
返回搜索WSL分发版本的IPV4/V6地址
使用 WSLPatcher
- 下载
- 解压文件到某目录,例如:
D:\Tools\WSLHostPatcher
- 先打开 WSL
- 然后运行
WSLHostPatcher\WSLHostPatcher.exe
,之后即可生效
自动运行
bash
# WSL ~/.profile
/mnt/d/Tools/WSLHostPatcher/WSLHostPatcher.exe # WSL 打开时自动运行
1
2
2
互相操作
Windows 文件管理器中打开 WSL
资源管理器地址栏中输入:\\wsl$
挂载位置
powershell
Get-ChildItem "HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss" -Recurse | ForEach-Object {
$distro_name = ($_ | Get-ItemProperty -Name DistributionName).DistributionName
$distro_dir = ($_ | Get-ItemProperty -Name BasePath).BasePath
Write-Output "Distribution: $distro_name"
Write-Output "Directory: $distro_dir"
}
1
2
3
4
5
6
2
3
4
5
6
powershell
wsl --unregister <DistroName>
1
DANGER
This command will permanently remove the WSL distribution, including all its files, configurations, and data. Be cautious before running this command, as the action cannot be undone. Let me know if you need further assistance!