Note: Migrate to Debian before Ubuntu 20.04 ends support (April, 2025).
- Windows 10 1809+
缺省为WSL1
wsl -l -v
在powerShell的管理员模式下运行命令!
安装/卸载
ON:
Control Panel -> Uninstall a program -> Turn Windows features on or off,
勾选“Windows Subsystem for Linux”
Ubuntu
-
从AppxBundle提取appx.
Add-AppxPackage .\Ubuntu_2004.xxx.appx
卸载
如果“普通”方式不工作,请使用“命令行”。
-
普通 右击“Ubuntu xxx” 图标,选择“Uninstall”即可。
wslconfig /u
Debian
Add-AppxPackage .\DistroLauncher-Appx_1.12.2.0_x64.appx
WSL2
- Enable Virtual Machine feature
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
Reboot your Windows 10 host
- WSL Linux kernel update package
wsl --update
- Install Click the “Debian” icon to install Debian. This takes some time.
Set a username and password for your Debian GNU/Linux installation when prompted
You are now logged in to your Debian system in command line mode
exec
enter wsl:
wsl --shutdown
wsl -u root
sources list
- network temporary failure resolving
echo "nameserver 8.8.8.8
nameserver 8.8.4.4" | sudo tee /etc/resolv.conf > /dev/null
- update
echo "deb http://mirrors.163.com/debian/ bookworm main non-free contrib
deb http://mirrors.163.com/debian/ bookworm-updates main non-free contrib
deb-src http://mirrors.163.com/debian/ bookworm main non-free contrib
deb-src http://mirrors.163.com/debian/ bookworm-updates main non-free contrib
deb http://mirrors.163.com/debian-security/ bookworm-security main non-free contrib
deb-src http://mirrors.163.com/debian-security/ bookworm-security main non-free contrib" > /etc/apt/sources.list && \
apt update -y
usrmerge
- install
apt install usrmerge
umount lib
If the following error message is displayed, it means v1 is mounting “/lib/modules”.
FATAL ERROR:
/lib/modules/ is a mount point.
Probably this system is using User Mode Linux or some variant of Xen.
To continue the conversion please unmount /lib/modules/ (try the command
'umount -l /lib/modules/') and then try again.
Do not forget to reboot after the conversion is complete to have it
mounted again.
umount it:
umount -l /lib/modules
Upgrade Debian 11 to 12
apt upgrade -y
apt dist-upgrade -y
apt autoremove -y
使用
更改源列表:
sudo vi /etc/apt/sources.list
http://archive.ubuntu.com -> https://mirrors.aliyun.com/ubuntu/
文件互访
首先,使用windows记事本,建立一个testTxtFile.txt;
然后,在WSL查看文件内容。
cd /mnt/c/Users/tdtc/
vi testTxtFile.txt
最后,用WSL重命名文件名:
mv testTxtFile.txt testFile.txt
在windows就可以看到重命名的testFile.txt。
访问WSL服务
WSL与windows 10共有端口,所以Windows 10已使用的端口,不要再分配给WSL
首先,在wsl中启动nginx;
sudo service nginx start
然后访问(回环地址):127.0.0.1:90