WSL Sparse does not work at all.
- Dominant language
- C++
- Stars
- 33.7k
- Forks
- 1.8k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 116
Description
### Windows Version
Microsoft Windows [Version 10.0.19045.4894]
### WSL Version
2.2.4.0
### Are you using WSL 1 or WSL 2?
- [X] WSL 2
- [ ] WSL 1
### Kernel Version
5.15.153.1-microsoft-standard-WSL2
### Distro Version
Ubuntu 22.04
### Other Software
_No response_
### Repro Steps
# Sparse does not work.
Ubuntu disk space (.vhdx file) shows ```118gbs``` in windows 10.
In Ubuntu: ```/ncdu / --exclude /mnt ``` shows ```64gbs```
Powershell(admin): ```notepad "$env:USERPROFILE/.wslconfig"```
.wslconfig:
```
[experimental]
sparseVhd=true
```
Powershell(admin):
```
wsl --list # list distros
wsl --manage --set-sparse true # enable sparse on vdisk
wsl --shutdown # restart wsl
wsl # restart wsl
```
Then when I check the size, it has not changed at all, still ```118gbs```.
# SOLUTION (MANUAL SHRINKING):
### for anyone who finds this in the future. Here is a way to resize the disk manually.
Powershell (admin):
```
FIRST BACKUP YOUR VHDX FILE
wsl --list # list distros
wsl --shutdown # Be patient and wait a bit for wsl to shutdown. It will eventually shutdown.
wsl --manage --set-sparse false
optimize-vhd -Path "" -Mode full
wsl --manage --set-sparse true
```
Then test if the VHDX file (wiztree) has shrunk and your distro can run.
### Expected Behavior
Reclaim disk space in Windows 10.
### Actual Behavior
The sparseVhd setting does not reclaim disk space in Windows 10.
### Diagnostic Logs
_No response_
Contributor guide
Research direction
Start by reproducing the reported Windows 10 behavior with .wslconfig's sparseVhd=true, then run the listed wsl --manage and wsl --shutdown commands and compare the VHDX size. Check whether the sparse setting actually reclaims space; done means the WSL VHDX shrinks while the distro remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- powershell
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100