Resolving Excessive C Drive Space Usage by WSA or WSL

因为我电脑一开始分区只给C盘分了100G,还加了Bitlocker加密,所以搞得现在空间不够用,而且还没法扩容(因为有BitLocker,没法扩容)。所以只好把安装的软件往外面迁,但是WSA是个占空间的大户,而且微软一如既往的不提供迁移方法,只好自己想办法解决。
同时,此办法也适用于对WSA,WSL有备份需求的用户。

WSA迁移方法

在文件浏览器中打开%LocalAppData%\Packages\MicrosoftCorporationII.WindowsSubsystemForAndroid_8wekyb3d8bbwe\LocalCache
其中userdata.vhdx文件是WSA的虚拟硬盘,安装的APP都在这个文件里。

用fastcopy复制到其他位置,再把原来位置的VHDX文件删除就可以了。
这里举例复制到Z:\WSA_VHDX

用fastcopy复制VHDX文件

然后进入有管理员权限的cmd,创建链接。
注意一定是cmd,powershell没有mklink指令

1
mklink userdata.vhdx Z:\WSA_VHDX\userdata.vhdx

用mklink创建软链接

WSL迁移方法

基本上和WSA迁移方法一致,不同在于VHDX路径不同。
不同Linux发行版的VHDX存储路径不同,用Ubuntu20.04LTS举例,它的VHDX存储在%LocalAppData%\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState下的ext4.vhdx里面,迁移其他到位置就好了。

注意事项

迁移前需要关闭对于软件,不然会提示文件打开,不能删除

WSA关闭方法

安装完WSA,会有一个绿色图标的应用,叫Windows Subsystem for Android,里面有个开关是关闭WSA。

WSL关闭方法

进入powershell或者cmd,输入wsl --shutdown

Since I initially partitioned only 100GB for the C drive on my computer and also added BitLocker encryption, I now face insufficient space and cannot expand it (due to BitLocker preventing expansion). Therefore, I had to move installed software to other drives. However, WSA (Windows Subsystem for Android) is a major space hog, and, as usual, Microsoft does not provide a migration method, so I had to figure out a solution myself.
Additionally, this method is also suitable for users who need to back up WSA or WSL.

WSA Migration Method

Open File Explorer and navigate to %LocalAppData%\Packages\MicrosoftCorporationII.WindowsSubsystemForAndroid_8wekyb3d8bbwe\LocalCache.
The userdata.vhdx file is the virtual hard disk for WSA, containing all installed apps.

Use fastcopy to copy it to another location, then delete the VHDX file from its original location.
Here’s an example of copying it to Z:\WSA_VHDX:

Copying VHDX file with fastcopy

Then, open cmd with administrative privileges and create a symbolic link.
Note: It must be cmd, as PowerShell does not have the mklink command.

1
mklink userdata.vhdx Z:\WSA_VHDX\userdata.vhdx

Creating a symbolic link with mklink

WSL Migration Method

This is essentially the same as the WSA migration method, with the only difference being the VHDX file path.
The VHDX storage path varies for different Linux distributions. For example, Ubuntu 20.04 LTS stores its VHDX at %LocalAppData%\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState in a file named ext4.vhdx. Just migrate it to another location.

Important Notes

Before migration, ensure the corresponding software is closed; otherwise, you’ll be prompted that the file is in use and cannot be deleted.

How to Close WSA

After installing WSA, there’s a green-tinted app called Windows Subsystem for Android, which has an option to turn off WSA.

How to Close WSL

Open PowerShell or cmd and enter wsl --shutdown.


Resolving Excessive C Drive Space Usage by WSA or WSL
https://tokisaki.top/blog/resolution-wsa-wsl-usage-much-system-space/
作者
Tokisaki Galaxy
发布于
2021年12月25日
许可协议