How do I resolve my WSL virtual disk compression issue?

Wanessa Karoline 0 Reputation points
2024-04-22T14:54:32.0933333+00:00

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.

Captura de tela 2024-04-22 114915

Figure 2.

Captura de tela 2024-04-22 113425

Figure 3.

Captura de tela 2024-04-22 114034

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,936 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Zijian Meng 0 Reputation points
    2024-07-02T18:58:40.8433333+00:00

    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

    0 comments No comments