Access Mobile Device Filesystem from WSL?

Solution 1:

I was able to get this working using the new USB/IP feature in WSL, along with jmtpfs.

USB/IP

See the official Microsoft docs for WSL2 USB/IP support. Note, however, that the exact steps will depend on:

  • Whether you are running Windows 10 or Windows 11. On Windows 11, you can just wsl --update to the latest kernel which has USB/IP support.

    Under Windows 10, you'll apparently need to build your own kernel from the WSL2 kernel sources. See Building your own USBIP enabled WSL 2 kernel in the usbipd-win project doc for the exact features to enable in menuconfig.

  • As with most things, directions for Ubuntu are standard. See my post on Debian for the changes needed for that distro.

  • The instructions from Microsoft and the usbipd-win project both assume that you are using your default WSL distribution. If you have more than one distribution, and need to access it in a non-default one, you can still manually run usbip from within WSL2.

jmtpfs

Once you've shared your phone from Windows to WSL over USB/IP and can see it with lsusb, then you should be able to mount it using jmtpfs:

sudo apt install jmtpfs
sudo mkdir /media/android
sudo jmtpfs -o allow_other /media/android/

Refer to the jmtpfs readme for more info.

It seems that after unmounting, the USB/IP connection is "lost" or damaged, so I had to detach and attach the device again on the Windows side before I could try anything else with it.