Mike Slinn

Expanding the WSL virtual hard drive

Published 2024-02-12.
Time to read: 1 minutes.

This page is part of the posts collection, categorized under WSL.

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:

Shell
$ wsl.exe --shutdown

Expand VHD With Diskpart

The virtual disk was in %LocalAppData%\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\ext4.vhdx

Open a cmd.exe window with admininstrator privileges and run diskpart.

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 (continued)
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:

cmd.exe
$ wsl.exe

Now tell Linux to use all available space:

Shell
$ 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!



* indicates a required field.

Please select the following to receive Mike Slinn’s newsletter:

You can unsubscribe at any time by clicking the link in the footer of emails.

Mike Slinn uses Mailchimp as his marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp’s privacy practices.