How to Expand WSL 2 Virtual Hard Disks (VHDX) in Windows 11 Using PowerShell

The Windows Subsystem for Linux (WSL 2) stores distribution file systems inside dynamic Virtual Hard Disk (.vhdx) files. By default, WSL 2 allocates an initial maximum virtual size limit—typically 1TB or 256GB depending on the installation version. When compiling massive codebases, downloading large machine learning datasets, or managing extensive container images, this boundary can be reached, resulting in No space left on device errors. Expanding this boundary requires resizing the virtual disk header via PowerShell and extending the ext4 filesystem within Linux.

Locating the WSL 2 Virtual Disk Container

Before modifying disk partitions, identify the exact storage path of your distribution’s virtual disk file:

  1. Open an elevated PowerShell prompt by right-clicking the Start button and selecting Terminal (Admin).
  2. Shut down all running WSL distributions to ensure complete database lock release:
    wsl --shutdown
  3. Confirm that all instances have terminated:
    wsl --list --verbose
  4. Locate the ext4.vhdx file. Standard distributions store their virtual disks inside local app data packages:
    Get-ChildItem -Path "$env:LOCALAPPDATA\Packages" -Filter "ext4.vhdx" -Recurse -ErrorAction SilentlyContinue | Select-Object FullName

Expanding the VHDX Header Using Diskpart via PowerShell

Use the Windows diskpart utility within PowerShell to increase the maximum allowable size of the virtual hard disk:

# Define the absolute path to your distribution VHDX file
$vhdxPath = "$env:LOCALAPPDATA\Packages\CanonicalGroupLimited.Ubuntu22.04LTS_79rhkp1fndgsc\LocalState\ext4.vhdx"

# Define the target maximum capacity in megabytes (e.g., 2048000 MB = ~2TB)
$newSizeMB = 2048000

# Create a temporary script file for diskpart execution
$diskpartScript = @"
select vdisk file="$vhdxPath"
expand vdisk maximum=$newSizeMB
"@

$diskpartScript | Out-File -FilePath "$env:TEMP\expand_wsl.txt" -Encoding ascii

# Execute diskpart with the configuration script
diskpart /s "$env:TEMP\expand_wsl.txt"

# Remove the temporary script
Remove-Item "$env:TEMP\expand_wsl.txt"

The console will output DiskPart successfully expanded the virtual disk file upon completion.

Extending the ext4 Filesystem Inside WSL 2

Expanding the virtual hard disk container increases the raw volume size, but the underlying Linux ext4 filesystem requires resizing to recognise the newly unallocated sectors:

  1. Launch your WSL 2 distribution from the terminal:
    wsl -d Ubuntu
  2. Identify the root block device and mounted partitions:
    lsblk

    The output displays the physical disk (typically /dev/sdX) reflecting the newly expanded raw capacity.

  3. Resize the primary ext4 filesystem directly using resize2fs:
    sudo resize2fs /dev/sdc

    Note: If your distribution utilizes partition tables (such as /dev/sdc1), expand the partition table boundary using sudo growpart /dev/sdc 1 before executing resize2fs.

Verifying New Filesystem Capacity

Confirm that the operating system registers the expanded volume:

df -h /

The available disk capacity will immediately reflect the expanded storage boundaries, allowing unconstrained package installations and container execution without system errors.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.