Skip to content

Instantly share code, notes, and snippets.

@itsdotscience
Created May 2, 2024 04:04
Show Gist options
  • Save itsdotscience/6431647a15c9ff626e780066845bb6fe to your computer and use it in GitHub Desktop.
Save itsdotscience/6431647a15c9ff626e780066845bb6fe to your computer and use it in GitHub Desktop.
#!/bin/bash
export WSLKERNEL=`uname -a | cut -d " " -f3 | cut -d "-" -f1`
export CHECKOUT_DIR=`linux-msft-wsl-$WSLKERNEL`
git clone https://github.com/microsoft/WSL2-Linux-Kernel.git --depth=1 -b $CHECKOUT_DIR
cd $WSLKERNEL
sudo make -j$(nproc) KCONFIG_CONFIG=Microsoft/config-wsl CONFIG_USB_STORAGE=m CONFIG_USB_UAS=m
sudo make -j$(nproc) KCONFIG_CONFIG=Microsoft/config-wsl CONFIG_USB_STORAGE=m CONFIG_USB_UAS=m modules
sudo make -j$(nproc) KCONFIG_CONFIG=Microsoft/config-wsl CONFIG_USB_STORAGE=m CONFIG_USB_UAS=m modules_install
cp arch/x86/boot/bzImage wsl-$WSLKERNEL
echo "Copy the above to the root of your USERPROFILE on the Windows sdie then Add in the [wsl] section of your .wslconfig the following, doubling all
kernel=c:\\users\\username\\wsl-$WSLKERNEL
Then run wsl --shutdown from Windows, wait a minut or so and star wsl again. Once you have your usb device passed you should see the storage device if not, try on the wsl side: modprobe usb-storage; modprobe uas"
@Komorebi-E
Copy link

@rs38 Commenting was from testing the \ to get the right output. I've removed the comments on the make commands - thank you for pointing it out.

Correct, it is a available fir USB mass storage. WSL2 with a custom built kernel cannot load modules with modprobe as the loadable module support is disabled when WSL2 is configured this way.

@rs38
Copy link

rs38 commented Oct 23, 2024

@Komorebi-E what's strange: to make the USB mass storage actually work with USBIPD and that custom kernel, I have to execute modprobe vhci_hcd in WSL2, which succeeds.
(and docker is failing)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment