查看当前WSL版本
wsl -l
PS C:\windows\system32> wsl -l 适用于 Linux 的 Windows 子系统分发: Ubuntu-22.04 (默认)
wsl --version
PS C:\windows\system32> wsl --version WSL 版本: 1.2.5.0 内核版本: 5.15.90.1 WSLg 版本: 1.0.51 MSRDC 版本: 1.2.3770 Direct3D 版本: 1.608.2-61064218 DXCore 版本: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows 版本: 10.0.19045.2965
查看运行中的子系统
wsl -l --running
PS C:\windows\system32> wsl -l --running 没有正在运行的分发。
运行子系统
wsl --distribution Ubuntu-22.04
PS C:\windows\system32> wsl --distribution Ubuntu-22.04 Welcome to Ubuntu 22.04.2 LTS (GNU/Linux 5.15.90.1-microsoft-standard-WSL2 x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s just raised the bar for easy, resilient and secure K8s cluster deployment. https://ubuntu.com/engage/secure-kubernetes-at-the-edge This message is shown once a day. To disable it please create the /home/yang/.hushlogin file.
停止子系统
wsl --terminate Ubuntu-22.04
或 wsl --shutdown
(停止当前子系统)
PS C:\windows\system32> wsl --terminate Ubuntu-22.04 操作成功完成。
备份子系统(需要先停止才能备份)
wsl --export Ubuntu-22.04 D:\temp\Ubuntu-22.04.tar
PS C:\windows\system32> wsl --export Ubuntu-22.04 D:\temp\Ubuntu-22.04.tar 正在导出,这可能需要几分钟时间。 操作成功完成。
卸载子系统
wsl --unregister Ubuntu-22.04
还原子系统
wsl --import <Distro> <InstallLocation> <FileName> [Options]
wsl --import Ubuntu-22.04 C:\WSL D:\temp\Ubuntu-22.04.tar
Note: 当还原后的子系统变为root权限了
改为默认用户权限
-
查看当前用户
ls /home/
-
尝试切换至用户权限
su 用户名
-
切换至root权限
sudo su
-
修改默认配置文件
-
备份
cp /etc/wsl.conf /etc/wsl.conf.bk
-
修改
vim /etc/wsl.conf
在最前面增加以下内容[user] default=用户名
-
重启wsl,在power shell中重启
# 查看当前运行的wsl wsl --list --running # 停止特定的wsl wsl -t Ubuntu-22.04 # 启动特定版本wsl wsl -d Ubuntu-22.04 #或者 # 停止当前所有运行wsl wsl --shutdowm # 启动默认wsl wsl
-