安装

WSL 是 windows subsystem for linux 的简称,可以理解为运行在windows上的一个虚拟机,微软应用商店安装即可

Make your Current Distro Run Systemd

1
2
3
4
curl -L -O "https://raw.githubusercontent.com/nullpo-head/wsl-distrod/main/install.sh"
chmod +x install.sh
./install.sh install
/opt/distrod/bin/distrod enable --start-on-windows-boot

固定IP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@echo on

net stop LxssManager
net start LxssManager
wsl -d Ubuntu -u root /opt/distrod/bin/distrod enable
wsl -d Ubuntu -u root ip addr del $(ip addr show eth0 ^| grep 'inet\b' ^| awk '{print $2}' ^| head -n 1) dev eth0
wsl -d Ubuntu -u root ip addr add 172.30.16.2/24 broadcast 172.30.16.255 dev eth0
wsl -d Ubuntu -u root ip route add 0.0.0.0/0 via 172.30.16.1 dev eth0

powershell -c "Get-NetAdapter 'vEthernet (WSL)' | Get-NetIPAddress | Remove-NetIPAddress -Confirm:$False; New-NetIPAddress -IPAddress 172.30.16.1 -PrefixLength 24 -InterfaceAlias 'vEthernet (WSL)'; Get-NetNat | ? Name -Eq WSLNat | Remove-NetNat -Confirm:$False; New-NetNat -Name WSLNat -InternalIPInterfaceAddressPrefix 172.30.16.0/24;"

wsl -d Ubuntu -u root systemctl restart sshd

@timeout /T 8 /NOBREAK

wsl命令

查看正在运行系统

1
wsl -l --running

关闭运行系统

1
wsl --terminate debian

wsl备份还原

备份

1
wsl --export Debian debian.tar

还原

1
wsl --import Debian E:\environment\wsl\debian d:debian.tar

文件夹无访问权限

1
2
C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps\Debian.exe config --default-user root
wsl --shutdown