shell@sanyue:~$ cat /etc/resolv.conf
# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateResolvConf = false
nameserver 172.19.112.1
shell@sanyue:~$

/usr/lib/wsl/lib/ 文件位置

初始化

  • 配置代理
wsl: 检测到 localhost 代理配置,但未镜像到 WSL。NAT 模式下的 WSL 不支持 localhost 代理。
创建.wslconfig。路径为`C:\Users\Administrator\.wslconfig`
使用vscode创建
该wsl是全局的,对所有的wsl实例都有效

.wslconfig

   [wsl2]
   localhostForwarding=true
   networkingMode=mirrored
  • 移动wsl的位置
  1. 查看wsl虚拟机的名称状态
wsl -l -v
  1. 停止wsl
wsl --shutdown
  1. 创建一个新目录存放新的wsl(eg: E:\Ubuntu_WSL)
wsl --export Ubuntu-22.04 E:\Ubuntu_WSL\Ubuntu.tar
  1. 导出虚拟机的备份
wsl --export Ubuntu-22.04 E:\Ubuntu_WSL\Ubuntu.tar
  1. 在 E:\Ubuntu_WSL 目录下创建一个备份文件 Ubuntu.tar
  2. 注销原有的wsl
wsl --unregister Ubuntu-22.04
  1. 将备份文件恢复到E:\Ubuntu_WSL目录下
wsl --import Ubuntu-22.04 D:\Ubuntu_WSL D:\Ubuntu_WSL\Ubuntu.tar
  1. 恢复默认用户( your_username 是你在 WSL 中的用户名)
Ubuntu2204 config --default-user your_username

 参考知乎