# Resize VHD
# ###############
# see: https://docs.microsoft.com/en-us/windows/wsl/vhd-size
#
#1 open powershell as admin
#Terminate WSL
wsl --shutdown
#find your distribution installation
packageGet-AppxPackage -Name "*Ubuntu*" | Select PackageFamilyName
#Copy the path to that file, it should look something like %LOCALAPPDATA%\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79xxxx\LocalState\ext4.vhdx
# This path will be called "<pathToVHD>" below
# ----# https://learn.microsoft.com/en-us/windows/wsl/disk-space#how-to-locate-the-vhdx-file-and-disk-path-for-your-linux-distribution
#find your distribution installation.
#replace <distribution-name> with your Ubuntu Version, for example Ubuntu-22.04
(Get-ChildItem -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Lxss | Where-Object { $_.GetValue("DistributionName") -eq '<distribution-name>' }).GetValue("BasePath") + "\ext4.vhdx"
#Copy the path to that file, it should look something like %LOCALAPPDATA%\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79xxxx\LocalState\ext4.vhdx
# This path will be called "<pathToVHD>" below
# -------------------------#start diskpartdiskpart# ----------
diskpart
#inside diskpart console
#select disk
DISKPART> Select vdisk file="<pathToVHD>"
#check details
DISKPART> detail vdisk
#(optional) shrink size
DISKPART> compact vdisk
#expand for example to 512GB <sizeInMegaBytes>=512000
#Note: WSL2 and Ubuntu 22.04 has default maximum size from harddisk
DISKPART> expand vdisk maximum=512000
#exit
DISKPART> exit
# ----------
#start WSL from powershell
sudo mount -t devtmpfs none /dev
# "/dev: none already mounted on /dev." warning can be ignored
mount | grep ext4
#resize fs to 512GB <sizeInMegaBytes>=512000M
sudo resize2fs /dev/sdb 512000M |