Skip to content

Instantly share code, notes, and snippets.

@igoforth
Created January 4, 2023 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igoforth/5d6315489f4401dc380fe306a525a998 to your computer and use it in GitHub Desktop.
Save igoforth/5d6315489f4401dc380fe306a525a998 to your computer and use it in GitHub Desktop.
Mounting VHD into WSL2
$number = $((Mount-DiskImage -ImagePath "D:\Data\VirtualBox VMs\WSL2 VHD\wsl2.vhdx" -PassThru | Get-Disk).Number)
$diskDrive = "\\.\PHYSICALDRIVE$number"
$bashDiskDrive = "PHYSICALDRIVE$number" + "p1"
wsl --mount $diskDrive -p 1
# remove previously created symlink
wsl rm -rf /mnt/wsl/vhd_data
# add new symlink
wsl ln -s /mnt/wsl/$bashDiskDrive /mnt/wsl/vhd_data
# Remember this line for our next part
# Start-Process "C:\Program Files\Docker\Docker\Docker Desktop.exe"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment