一、安裝
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