克隆 WSL 发行版

发布: (2026年2月19日 GMT+8 08:29)
2 分钟阅读
原文: Dev.to

Source: Dev.to

为什么要克隆 WSL 发行版?

你已经花了数小时来设置一个 WSL 发行版——安装软件包、配置 shell、调优开发环境。在尝试风险较大的操作(如大版本升级、新工具或独立项目)之前,你可以创建一个 克隆 来保护当前的工作环境。

导出 & 导入(tar)

基本工作流程如下:

# Export the current distro to a tar file
wsl --export Ubuntu C:\Temp\ubuntu-clone.tar

tar 文件包含文件系统的完整快照(软件包、用户账户、配置文件、主目录等)。
对于大型发行版,这可能需要几分钟,且 tar 文件的大小大致等于发行版内部已使用的磁盘空间。

# Import the tar as a new distribution
wsl --import Ubuntu-Dev "D:\WSL\Ubuntu-Dev" C:\Temp\ubuntu-clone.tar

参数

参数含义
Ubuntu-Dev克隆后发行版的名称
D:\WSL\Ubuntu-Dev将创建新 VHDX 的目录
C:\Temp\ubuntu-clone.tar导出步骤生成的 tar 文件

恢复默认用户

从 tar 存档导入时,WSL 默认以 root 身份登录。通过编辑 /etc/wsl.conf 来设置默认用户:

# Start the clone as root
wsl -d Ubuntu-Dev -u root

# Append the user section if it does not exist
grep -q "^\[user\]" /etc/wsl.conf 2>/dev/null || cat >> /etc/wsl.conf *
0 浏览
Back to Blog

相关文章

阅读更多 »

重命名 WSL 发行版

重命名 WSL 发行版 – 完整指南 您从 Microsoft Store 安装了 Ubuntu,WSL 将其命名为 Ubuntu‑24.04。您又安装了另一个,得到 Ub…

Apex B. OpenClaw,局部嵌入

本地嵌入用于私有记忆搜索。默认情况下,OpenClaw 的 memory search 会将文本发送到外部的 embedding API,通常是 Anthropic 或 OpenAI……

Apex 1. OpenClaw, 供应商历史

从 ChatGPT、Anthropic 和 Google Gemini 导入聊天记录。使用 OpenClaw,你可以做的最强大的事情之一是 bootstrap 你的记忆……