Skip to content

Instantly share code, notes, and snippets.

@rgkirch
Last active July 16, 2023 17:59
Show Gist options
  • Save rgkirch/c033d1948e290e30329f6f43a85da11a to your computer and use it in GitHub Desktop.
Save rgkirch/c033d1948e290e30329f6f43a85da11a to your computer and use it in GitHub Desktop.
wsl2 usbip

don’t forget to run these at some point

flutter doctor --android-licenses
sdkmanager --licenses
JAVA_HOME=/home/me/jdk-11 # where did you install java? or maybe are you using the one bundled with android studio?
PATH=/home/me/jdk-11/bin:$PATH
ANDROID_HOME=/usr/local/android_sdk
# ANDROID_SDK_ROOT=/usr/local/android_sdk # ANDROID_SDK_ROOT, which also points to the SDK installation directory, is deprecated
PATH=/usr/local/android_sdk/platform-tools:$PATH # idk if you need these on the path but it does save some typing
PATH=/usr/local/android_sdk/build-tools/31.0.0:$PATH # idk if you need these on the path but it does save some typing
PATH=/usr/local/android_sdk/cmdline-tools/latest/bin:$PATH # idk if you need these on the path but it does save some typing
PATH=/usr/local/android_sdk/emulator:$PATH # idk if you need these on the path but it does save some typing
WSL_HOST=$(tail -1 /etc/resolv.conf | cut -d' ' -f2)
ADB_SERVER_SOCKET=tcp:$WSL_HOST:5037
PATH=/home/me/flutter/bin:$PATH

in elevated (admin) windows powershell

> winget install --id "dorssel.usbipd-win"

and maybe restart your computer because you installed a driver (i read that somewhere)

and then again in elevated (admin) powershell make sure wsl2 is up to date

> wsl --update

in wsl2 ubuntu

$ sudo apt install linux-tools-virtual hwdata
$ sudo update-alternatives --install /usr/local/bin/usbip usbip `ls /usr/lib/linux-tools/*/usbip | tail -n1` 20

plug something into your computer. ymmmv using a usb hub.

admin powershell

> usbipd wsl list
usbipd wsl list
BUSID  VID:PID    DEVICE                                                        STATE
9-1    abcd:1234  Pixel Whatever                                              Not attached

consider tailing dmesg in wsl2 before you attach the usb thing to wsl2

$ dmesg --follow

admin powershell

> usbipd wsl attach --busid 9-1
usbipd: info: Using default WSL distribution 'Ubuntu'; specify the '--distribution' option to select a different one.

admin powershell

> usbipd wsl list
usbipd wsl list
BUSID  VID:PID    DEVICE                                                        STATE
9-1    abcd:1234  Pixel Whatever                                              Attached - Ubuntu

and then in ubuntu wsl2

$ lsusb
Bus 001 Device 002: ID abcd:1234 Google Pixel Whatever

neat.

if you were tailing dmesg you see some stuff. e.g. I see

$ dmesg --follow
[   62.792574] vhci_hcd vhci_hcd.0: pdev(0) rhport(0) sockfd(3)
[   62.793094] vhci_hcd vhci_hcd.0: devid(327681) speed(3) speed_str(high-speed)
[   62.793533] vhci_hcd vhci_hcd.0: Device attached
[   63.138634] usb 1-1: new high-speed USB device number 2 using vhci_hcd
[   63.298482] usb 1-1: SetAddress Request (2) to port 0
[   63.345331] usb 1-1: New USB device found, idVendor=abcd, idProduct=1234, bcdDevice= 4.09
[   63.345795] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[   63.346090] usb 1-1: Product: Pixel Whatever
[   63.346289] usb 1-1: Manufacturer: Google
[   63.346427] usb 1-1: SerialNumber: XYZFOOBAR

examples on the internet show /dev/ttyACMX or /dev/ttySX but I didn’t see that

flutter devices and adb devices didn’t show anything until I restarted the adb server

$ adb devices
List of devices attached

$ sudo adb kill-server
sudo adb start-server
[sudo] password for me:
* daemon not running; starting now at tcp:5037

* daemon started successfully
$ adb devices
List of devices attached
abcdefghijklmn        unauthorized

then I had to hit the button on my device to allow the host to access it

$ adb devices
List of devices attached
abcdefghijklmn        device
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment