Published 2024-02-12.
Time to read: 1 minutes.
I ran out of room on my WSL2 virtual hard drive. Microsoft’s instructions worked perfectly to increase the virtual drive size.
Shut Down WSL
The following command work from WSL bash, and cmd, and PowerShell:
$ wsl.exe --shutdown
Expand VHD With Diskpart
The virtual disk was in %LocalAppData%\
Open a cmd.exe
window with admininstrator privileges and run diskpart
.
DISKPART> Select vdisk file="%LocalAppData%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\ext4.vhdx"
DISKPART> detail vdisk Device type ID: 0 (Unknown) Vendor ID: {00000000-0000-0000-0000-000000000000} (Unknown) State: Added Virtual size: 256 GB Physical size: 247 GB Filename: C:\Users\Mike Slinn\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\ext4.vhdx Is Child: No Parent Filename: Associated disk#: Not found.
The virtual disk was 256 GB (256,000 MB). I want it to be twice as big: 512,000 MB.
DISKPART> expand vdisk maximum=512000
100 percent completed
DiskPart successfully expanded the virtual disk file. DISKPART> exit
Leaving DiskPart...
Restart WSL and Run resize2fs
Now I restarted WSL from a cmd
window.
The following command work from WSL bash, and cmd, and PowerShell:
$ wsl.exe
Now tell Linux to use all available space:
$ sudo resize2fs /dev/sdc 512000M resize2fs 1.47.0 (5-Feb-2023) Filesystem at /dev/sdc is mounted on /; on-line resizing required old_desc_blocks = 32, new_desc_blocks = 63 The filesystem on /dev/sdc is now 131072000 (4k) blocks long.
Done!