Skip to content

Instantly share code, notes, and snippets.

@arvati
Last active June 23, 2024 20:17
Show Gist options
  • Save arvati/4eee1006d46d7ca373c11fde9c33e588 to your computer and use it in GitHub Desktop.
Save arvati/4eee1006d46d7ca373c11fde9c33e588 to your computer and use it in GitHub Desktop.
Using USB devices under WSL with usbipd-win and mount Disks

Mount Windows Disk under WSL:

sudo mount -t drvfs D: /mnt/d

Mount generic disk under WSL

Identify your disk

GET-CimInstance -query "SELECT * from Win32_DiskDrive"

or

wmic diskdrive list brief

Mount using bare option:

wsl --mount \\.\PHYSICALDRIVE1 --bare

Mount LUKS device like this:

sudo lsblk
sudo blkid /dev/sdd3
sudo cryptsetup luksOpen /dev/sdd3 my-device
sudo mkdir -p /somewhere
sudo mount /dev/mapper/my-device /somewhere

Under windows you may explorer like this:

\\wsl.localhost\Debian\somewhere

Mount partition:

wsl --mount \\.\PHYSICALDRIVE1 --partition 1 --type ext4 --name myDisk

Under wsl it will be mounted at:

ls /mnt/wsl/PHYSICALDRIVE1p1
# or if name specified
ls /mnt/wsl/myDisk

After use you can unmount:

wsl --unmount \\.\PHYSICALDRIVE1

If want to mount an VHD disk first make it an device (use your ):

Write-Output "\\.\PhysicalDrive$((Mount-VHD -Path <pathToVHD> -PassThru | Get-Disk).Number)"

VHD disks from wsl distros are saved at:
C:\Users[user]\AppData\Local\Packages[distro]\LocalState[distroPackageName]

wsl from microsoft store has option to mount VHD directly:

wsl --mount --vhd <pathToVHD>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment