C:\Program Files\WSL是系统自带的,与下面WSL功能是否启用无关,不能将基删除或移走,否则系统服务WSL Service将无法运行,wsl命令也无法执行。
Enable the WSL feature:
Install:
PS C:\Users\ZhangZhihui> wsl --install 正在安装: Ubuntu 已安装 Ubuntu。 正在启动 Ubuntu... Installing, this may take a few minutes... Please create a default UNIX user account. The username does not need to match your Windows username. For more information visit: https://aka.ms/wslusers Enter new UNIX username: zzh New password: Retype new password: passwd: password updated successfully Installation successful! To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details. Welcome to Ubuntu 24.04.1 LTS (GNU/Linux 5.15.167.4-microsoft-standard-WSL2 x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/pro System information as of Mon Jan 6 19:44:19 CST 2025 System load: 0.07 Processes: 32 Usage of /: 0.1% of 1006.85GB Users logged in: 0 Memory usage: 2% IPv4 address for eth0: 172.26.76.164 Swap usage: 0% This message is shown once a day. To disable it please create the /home/zzh/.hushlogin file.
The default location of WSL is on disk C. Move it to disk D:
Win + i to open Settings:
Backup the WSL2 Ubuntu:
PS C:\Users\ZhangZhihui> wsl --export Ubuntu D:\WSL2_Backups\backup_0.tar 正在导出,这可能需要几分钟时间。 操作成功完成。 PS C:\Users\ZhangZhihui> wsl --list --verbose NAME STATE VERSION * Ubuntu Stopped 2
Remove the WSL2 Ubuntu:
PS C:\Users\ZhangZhihui> wsl --unregister Ubuntu 正在注销。 操作成功完成。 PS C:\Users\ZhangZhihui> wsl --list --verbose 适用于 Linux 的 Windows 子系统没有安装的分发版。 使用 'wsl.exe --list --online' 列出可用的分发版 和 'wsl.exe --install <Distro>' 进行安装。 也可以通过访问 Microsoft Store 来安装分发版: https://aka.ms/wslstore 错误代码: Wsl/WSL_E_DEFAULT_DISTRO_NOT_FOUND
Move the app back to disk C:
Restore from backup:
PS C:\Users\ZhangZhihui> wsl --import Ubuntu D:\WSL2\Ubuntu D:\WSL2_Backups\backup_0.tar 正在导入,这可能需要几分钟时间。 操作成功完成。 PS C:\Users\ZhangZhihui> wsl --list --verbose NAME STATE VERSION * Ubuntu Stopped 2 PS C:\Users\ZhangZhihui> D: PS D:\> cd WSL2\Ubuntu PS D:\WSL2\Ubuntu> dir 目录: D:\WSL2\Ubuntu Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 2025/1/6 21:16 1354760192 ext4.vhdx PS D:\WSL2\Ubuntu> C: PS C:\Users\ZhangZhihui> wsl root@ZZHPC:/mnt/c/Users/ZhangZhihui# exit logout
Change default login user from root back to zzh:
PS C:\Users\ZhangZhihui> wsl root@ZZHPC:/mnt/c/Users/ZhangZhihui# cat /etc/wsl.conf [boot] systemd=true root@ZZHPC:/mnt/c/Users/ZhangZhihui# vi /etc/wsl.conf root@ZZHPC:/mnt/c/Users/ZhangZhihui# cat /etc/wsl.conf [boot] systemd=true [user] default=zzh root@ZZHPC:/mnt/c/Users/ZhangZhihui# exit logout PS C:\Users\ZhangZhihui> wsl --shutdown Ubuntu PS C:\Users\ZhangZhihui> wsl To run a command as administrator (user "root"), use "sudo <command>". See "man sudo_root" for details. zzh@ZZHPC:/mnt/c/Users/ZhangZhihui$
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)