Before Optimize-VHD, ensure your disk of distro is not set as sparse. See this answer:
https://superuser.com/questions/1827953/reclaim-wsl2-disk-space-after-setting-it-to-sparse
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello! I have Windows Pro 11 and WSL2.
My VDH has 105G (Fig. 1) .and is taking up a lot of space on my SSD (C:) because I have already deleted files from my Ubuntu (which now only has 19G in \home), but the VHD remains with the same 105G storage, without freeing up space on my SSD. I have already run the command as an administrator in PowerShell so that it is automatically spaced with "wsl --manage Ubuntu -s true" and it returns that the operation was carried out successfully, but when checking the storage, both the SSD and the VDH, they continue the same (Fig. 2).
After that, I tried to compress the VHD with "Optimize-VHD", followed all possible instructions to activate Hyper-V and ensure that no WSL instance is in operation, but it returns me a failure when compressing the virtual visco with following message "Failed to open the attachment 'C:\Users\karoline\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu_79rhkp1fndgsc\LocalState\ext4.vhdx'. Error: 'The requested operation could not be completed due to a system limitation. virtual disk. Virtual hard disk files must be decompressed and decrypted.'." (Fig. 3).
Please, I would like a solution to my problem, what could I do in this case if I want to have the spaced storage of "ext4.vhdx" back to my SSD (C:) and have it automatically spaced as soon as I delete it an ubuntu file?
Figure 1.
Figure 2.
Figure 3.
Before Optimize-VHD, ensure your disk of distro is not set as sparse. See this answer:
https://superuser.com/questions/1827953/reclaim-wsl2-disk-space-after-setting-it-to-sparse