admin管理员组

文章数量:1655036

通过软连接的方式修改VHDX 文件的存放磁盘,达到缓解C盘存储压力的问题

软连接方式

$newLocation = "E:\WSL\Ubuntu-WSL2\"

cd ~\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState
wsl --shutdown

Optimize-VHD .\ext4.vhdx -Mode Full
mkdir $newLocation -Force
mv ext4.vhdx $newLocation
cd ..
rm LocalState
New-Item -ItemType SymbolicLink -Path "LocalState" -Target $newLocation

导出导入方式

关闭wsl

wsl --shutdown

查看系统信息 wsl -l -v

> wsl -l -v
  NAME            STATE           VERSION
* Ubuntu-20.04    Running         2

导出系统 wsl --export <DistroName> <PathToTarArchive>

wsl --export Ubuntu-20.04  E:\WSL\Ubuntu20.04-WSL2\ubuntu.tar

删除系统 wsl --unregister <DistroName>

wsl --unregister Ubuntu-20.04

导入系统 指定新的位置 wsl --import <DistroName> <PathToDistroNewDirectory> <PathToTarArchive>

wsl --import Ubuntu-20.04 E:\WSL\Ubuntu-WSL2 E:\WSL\Ubuntu20.04-WSL2\ubuntu.tar
wsl -l -v

设置默认用户

ubuntu2004.exe config --default-user xxx

参考

https://murrahjm.github.io/Exporting-WSL-data/
https://dev.to/milolav/manually-installing-wsl2-distributions-41b4
https://github/microsoft/WSL/issues/4699#issuecomment-660104214

本文标签: 磁盘