WSL使用说明

 一、安装

wsl --install -d ubuntu

二、 资源管理器切换

1. windows资源管理器中打开(linux目录)

\\wsl$

或者直接执行:

explorer.exe .  # 注意后缀.exe

2. linux查看windows目录

 cd /mnt

 三、 设置WSL2最大内存

在C:\Users\%UserName%目录下,新增.wslconfig文件

[wsl2]
processors=4
memory=4GB
swap=0
localhostForwarding=true

然后重启:

wsl --shutdown

 四、 重启WSL

net stop LxssManager
net start LxssManager

 五、修改WSL所在的位置为自定义的盘

1.查看已经安装的WSL实例

> wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Running         2

2.导出分发版到E盘

wsl --export Ubuntu E:\wsl-ubuntu.tar

3.注销当前分发版

wsl --unregister Ubuntu

4.重新导入并安装在E盘

wsl --import Ubuntu E:\ubuntu20.04 E:\wsl-ubuntu.tar --version 2

5. 设置默认登陆用户为安装时用户名

ubuntu config --default-user USERNAME

6. 删除wsl-ubuntu.tar

del E:\wsl-ubuntu.tar

 六、使用USB

参考资料:https://devblogs.microsoft.com/commandline/connecting-usb-devices-to-wsl/

1.windows宿主机安装usbipd-win

安装地址:https://github.com/dorssel/usbipd-win/releases

2.ubuntu子系统安装

sudo apt install linux-tools-5.4.0-77-generic hwdata
sudo update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/5.4.0-77-generic/usbip 20

3.windows命令行查看主机可以绑定到wsl的usb列表

> usbipd wsl list
BUSID  DEVICE                                                        STATE
1-5    Realtek USB 2.0 Card Reader                                   Not attached
1-7    USB2.0 HD UVC WebCam                                          Not attached
1-10   英特尔(R) 无线 Bluetooth(R)                                    Not attached
2-1    kevin, USB 大容量存储设备, ADB Interface                        Not attached
2-2    USB Serial Converter                                          Not attached
2-3    USB 输入设备, Madao Device                                     Not attached
2-4    Logitech USB Input Device, USB 输入设备                        Not attached

4.虚拟一个USB到WSL中

 usbipd wsl attach -b 1-10

5.WSL子系统中查看usb

$ lsusb
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 8087:0aaa Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

6.取消绑定USB

 usbipd wsl detach -b 1-10

七、启动SSH Server

$ sudo vim /etc/ssh/sshd_config

Port 22 #放开注释
PasswordAuthentication yes # no -> yes

$ sudo /etc/init.d/ssh start

# 首次启动如果报错
# sshd: no hostkeys available -- exiting
$ cd /etc/ssh
$ sudo ssh-keygen -A


$ ssh xx@127.0.0.1
# 或 ssh xx@localhost

 八、删除wsl子系统

wsl --unregister Ubuntu

 

posted on 2022-04-06 15:55  Netsharp  阅读(761)  评论(0编辑  收藏  举报

导航