wsl安装ubuntu并简单配置
安装及迁移
# 安装
wsl --install -d Ubuntu-22.04
-d 指定版本
# 迁移
wsl -l --all -v //看版本名称
wsl --export <版本名称> <导出路径> \\ 导出
wsl --unregister <发行版名称> \\ 注销原有的
wsl --import <自定义名称> <目标目录> <导出的路径> \\ 导入
wsl --import wsl-ubuntu-22.04 E:\VMs\wsl-ubuntu-22.04 E:\VMs\wsl-ubuntu-22.04.tar
配置
基本配置,随机贴上一些
sudo apt update && sudo apt-get update
sudo apt instal net-tools
网络配置
参考链接:
https://github.com/jay-waves/til/blob/main/System/Distributions/WSL/配置 - 从此开始.md
https://learn.microsoft.com/en-us/windows/wsl/networking
# 寻找wslconfig
windows在powershell中
cd ~
新建一个.wslconfig
此处是wsl的全局配置,只支持[wsl2]和[experimental]
# 寻找wsl.config
具体的某个wsl实例的配置需要在wsl.conf中设置
wsl.conf对于每个wsl实例都有,支持[automount], [network], [interop], and [user]
## 在wsl的linux中
cd /ect
cat wsl.conf
sudo vim wsl.conf
进行编辑即可
----------conf----------
# 自动挂载windows的固定驱动器
[automount]
enabled = true
root = /mnt
[user]
# 默认登录用户
default = <username>
[network]
# networkingMode NAT or mirrored(桥接模式)
networkingMode=NAT
# 是否使用windwos代理
autoProxy=true
#dnsTunneling,开启可以增加和vpn的兼容性
dnsTunneling = true
----------conf----------
su切换回普通用户
su - <username>
正常使用exit会关闭wsl,故使用su方法切换
BUG
1 路径问题
wsl: 检测到 localhost 代理配置,但未镜像到 WSL。NAT 模式下的 WSL 不支持 localhost 代理。
<3>WSL (681) ERROR: UtilTranslatePathList:2852: Failed to translate C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\bin
<3>WSL (681) ERROR: UtilTranslatePathList:2852: Failed to translate C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.4\libnvvp
<3>WSL (681) ERROR: UtilTranslatePathList:2852: Failed to translate C:\Windows\system32
<3>WSL (681) ERROR: UtilTranslatePathList:2852: Failed to translate C:\Windows
<3>WSL (681) ERROR: UtilTranslatePathList:2852: Failed to translate C:\Windows\System32\Wbem
<3>WSL (681) ERROR: UtilTranslatePathList:2852: Failed to translate C:\Windows\System32\WindowsPowerShell\v1.0\
...
本机的代理问题,具体为什么,可能是因为本机了代理之后,wsl不能正常访问windows的一些资源
解决
关闭windows的代理即可

浙公网安备 33010602011771号