Loading

解决WSL迁移到D盘后,C盘内存还是老是不足的方法

将window的子系统迁移如果是通过Appstore安装的话可以在设置-应用-更改存储
来一键进行迁移保存位置

默认情况下,WSL会将其发行版(Ubuntu、Docker-Desktop等等)安装在C盘的用户个人资料文件夹下,具体路径通常为:%USERPROFILE%\AppData\Local\Packages<发行版名称>\LocalState\ext4.vhdx。随着在WSL环境中配置的内容如Docker镜像等越来越多,其对应的虚拟磁盘文件体积会持续增大,这往往会导致C盘空间被大量占用,甚至出现空间不足的警告。

通过以下脚本可以迁移WSL中发行版的 vhdx 文件到其他位置。targetPath 是迁移的目目的地文件夹路径。

wsl --list -v # 获取发行版名称,此处以Ubuntu-24.04为例

$targetPath = "D:\Ubuntu-24"

if (!(Test-Path $targetPath)) { New-Item -Path $targetPath -ItemType Directory | Out-Null }

wsl --shutdown

wsl --manage Ubuntu-24.04 --move "$targetPath"
posted @ 2025-07-24 13:48  hllqk  阅读(442)  评论(0)    收藏  举报