Commit c53021
2024-03-31 14:01:36 Qwas: 新增 WSL导入导出/dev/null .. "b/WSL\345\257\274\345\205\245\345\257\274\345\207\272(\345\244\207\344\273\275\346\201\242\345\244\215).md" | |
@@ 0,0 1,80 @@ | |
+ | # WSL导入导出(备份恢复) |
+ | |
+ | ## 备份当前实例 |
+ | |
+ | ```sh |
+ | wsl --export Ubuntu C:\wsl-backup\backup-ubuntu.tar.gz |
+ | # Unregister 取消注册分发版并删除根文件系统。 |
+ | wsl --unregister Ubuntu |
+ | ``` |
+ | |
+ | :::danger |
+ | --unregister 会删除对应文件系统,无法找回 |
+ | ::: |
+ | |
+ | |
+ | ## 安装一个全新版本 Ubuntu |
+ | |
+ | ```sh |
+ | wsl --install -d Ubuntu |
+ | ``` |
+ | |
+ | ## 备份新安装的 Ubuntu |
+ | |
+ | ```sh |
+ | wsl --export Ubuntu C:\wsl-backup\ubuntu-empty.tar.gz |
+ | ``` |
+ | |
+ | ## 导入已备份的新 Ubuntu 系统 |
+ | |
+ | 使用不同的名称和路径,实现多个实例共存 |
+ | |
+ | ```sh |
+ | wsl --import <Distro> <InstallLocation> <FileName> [options] |
+ | ``` |
+ | |
+ | ```sh |
+ | wsl --import ubuntu2 C:\wsl-backup\ubuntu2 C:\wsl-backup\ubuntu-empty.tar.gz |
+ | ``` |
+ | |
+ | ```sh |
+ | wsl --import qwas C:\wsl-backup\qwas C:\wsl-backup\ubuntu-empty.tar.gz |
+ | ``` |
+ | |
+ | ## 运行指定版本 |
+ | |
+ | ```sh |
+ | wsl -d ubuntu2 |
+ | ``` |
+ | |
+ | ```sh |
+ | wsl -d qwas |
+ | ``` |
+ | |
+ | ## 导入旧的 Ubuntu |
+ | |
+ | ```sh |
+ | wsl --import default-ubuntu C:\wsl-backup\default-ubuntu C:\wsl-backup\backup-ubuntu.tar.gz |
+ | ``` |
+ | ## 其他 |
+ | |
+ | ### 设置默认版本 |
+ | |
+ | ```sh |
+ | wsl --set-default default-ubuntu |
+ | ``` |
+ | |
+ | ### 修改用户 |
+ | |
+ | 手动导入的 Ubuntu,默认以 root 用户登录,指定用户,需要修改 `/etc/wsl.conf` 文件,加入下面内容 |
+ | |
+ | ```ini |
+ | [user] |
+ | default=<username> |
+ | ``` |
+ | |
+ | ## 参考 |
+ | |
+ | [WSL挂载多个Ubuntu系统_wsl多个子系统-CSDN博客](https://blog.csdn.net/weixin_44286143/article/details/134047182) |
+ | |
+ | [Installing multiple instances of Ubuntu in WSL2 | Mourtada.se](https://www.mourtada.se/installing-multiple-instances-of-ubuntu-in-wsl2/) |