ZhangZhihui's Blog  

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$
复制代码

 

posted on   ZhangZhihuiAAA  阅读(41)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
 
点击右上角即可分享
微信分享提示