microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.34k stars 814 forks source link

[WSL 2] Attached USB/IP device can't be detected by WSL applications #5165

Closed ghost closed 4 years ago

ghost commented 4 years ago

Hello,

Finally I have enabled USB device support in WSL 2. I can attach USB devices with WSL 2 environment including my iPhone with the help of usbip project. https://github.com/cezanne/usbip-win

But problem is applications installed inside WSL (CLI Tools to work with Phone) can't detect attached device (phone). I have attached the device properly and it's showing there when I give below command: lsusb p

But those tools can't detect the device.

I'm confused that USB/IP can attach usb devices ok but applications inside WSL can't access/detect those devices?

Environment Windows 10 x64 Build 2004 (19041.207) WSL 2 (Ubuntu 20.04) USB Device - iPhone

onomatopellan commented 4 years ago

This is for storage devices and I didn't try it but maybe something will be of some help:

https://github.com/jovton/USB-Storage-on-WSL2

ghost commented 4 years ago

This is for storage devices and I didn't try it but maybe something will be of some help:

https://github.com/jovton/USB-Storage-on-WSL2

@onomatopellan This method made my WSL stopped working. It's throwing error while I'm trying to enable systemd:

sh: /usr/sbin/daemonize: No such file or directory

And WSL is not starting after that.

although the package demonize is installed. is there any other way to enable systemd in WSL?

onomatopellan commented 4 years ago

You are right, that tutorial is for Ubuntu 18.04 and daemonize installs in /usr/sbin/daemonize. In Ubuntu 20.04 daemonize now is installed in /usr/bin/daemonize instead.

You can do from cmd wsl.exe -d Ubuntu-20.04 -u root -e nano /usr/sbin/enter-systemd-namespace and change THIS line so it starts with /usr/bin/daemonize

ghost commented 4 years ago

You are right, that tutorial is for Ubuntu 18.04 and daemonize installs in /usr/sbin/daemonize. In Ubuntu 20.04 daemonize now is installed in /usr/bin/daemonize instead.

You can do from cmd wsl.exe -d Ubuntu-20.04 -u root -e nano /usr/sbin/enter-systemd-namespace and change THIS line so it starts with /usr/bin/daemonize

@onomatopellan Thanks, issue solved. I can attach pendrive now. Will this method work for iPhone/Android devices too? or only pendrive etc. storage devices?

onomatopellan commented 4 years ago

For android devices you can try using adb. #4692

Marietto2008 commented 4 years ago

@thedozo : kinect is not an usb storage device. the new method is not good for me. Anyway,I don't understand what's the utility of this method. what means usb storage device ? I've installed mate desktop and I can access to my USB storage devices without probs. I mean,usb disks. what else ? anyway,can u help me or not ? I'm not able to install the usb modules that I have configured inside the kernel. This is what happens to me :

https://www.reddit.com/r/bashonubuntuonwindows/comments/gcbjfi/module_usbcore_not_found_in_directory/ ;

do u want to record a video,showing how you have solved this prob ? please. thanks.

ghost commented 4 years ago

@Marietto2008 my requirement is iPhone which is also not an USB storage device. I'm still looking for a way to connect it with WSL. the new method is fine for pendrive etc. but not for iPhone like devices. This is how i solve my USB modules problem:

1) enable WSL 2 2) Install WSL 2 kernel from this link: https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel 3) Download 4.19.104 from Github. 4) Compile the kernel with usb modules. 5) Boot from bzImage file and .wslconfig file. 6) Load USB modules with startusb script.

You have skipped point #2 while installing Ubuntu. Also you said you can boot from vmlinux, but not from bzImage. So your prorcess is different then me. Now you can remove Ubuntu including all custom kernel and follow above mentioned steps to check if it helps.

Marietto2008 commented 4 years ago

I have already installed the kernel update. your instructions does not help me. I do that already. I need a recorded video. I'm stuck. If u do that,maybe I can help you for the next step,because it seems that we want to achieve the same goal.

Marietto2008 commented 4 years ago

I can also record another video showing how is my new workflow,because until some day ago I booted the vm without starting with the kernel 84,but now I do that. despite this,it does not work.

Marietto2008 commented 4 years ago

with which ubuntu version do you work ? did u get ubuntu 20 from ms store ?

Marietto2008 commented 4 years ago

ohhh finally I've understood my error and I've been able to do that.

ghost commented 4 years ago

ohhh finally I've understood my error and I've been able to do that.

@Marietto2008 so now your usb modules are working?

Marietto2008 commented 4 years ago

root@DESKTOP-N9UN2H3:/usr/src/4.19.104-microsoft-standard# ./startusb.sh 172.21.128.1

Marietto2008 commented 4 years ago

I've found the solution for this problem by myself. I wonder why I didn't read it by anyone all around (it wasn't explained even in the guide). It's not good to take a lot of things for granted,thinking that on internet there are only skilled people. think about this,you,man (or girl) who is reading me.

it works like this :

1) I start with ubuntu 20 and kernel 4.19.104

2) I compile the new kernel (again it should be 104,enabling usb modules and kvm)

3) wsl --shutdown

4) on /users/marietto2020 : I change the old kernel with which I have booted ubuntu 20 with the new kernel that I have compiled (by declaring it on the .wslconfig file). When I restart ubuntu,I can do :

!/bin/bash

sudo modprobe usbcore

sudo modprobe usb-common

sudo modprobe hid-generic

sudo modprobe hid

sudo modprobe usbnet

sudo modprobe cdc_ether

sudo modprobe rndis_host

sudo modprobe usbserial

sudo modprobe usb-storage

sudo modprobe cdc-acm

sudo modprobe ftdi_sio

sudo modprobe usbip-core

sudo modprobe vhci-hcd

echo $(cat /etc/resolv.conf | grep nameserver | awk '{print $2}')
Marietto2008 commented 4 years ago

at the end,even usbip worked here : hip hip hurra' for me.

usbip: debug: C:\work\usbip-win\userspace\src\usbipd\usbipd_sock.c:38:[build_sockfd] opening 0.0.0.0:3240 usbip: info: listening on 0.0.0.0:3240 usbip: info: connection from 192.168.1.6:50720 usbip: info: recv_pdu: received request: 0x8003 - attach device usbip: debug: C:\work\usbip-win\userspace\src\usbipd\usbipd_import.c:18:[forwarder_stub] stub forwarding started usbip: debug: C:\work\usbip-win\userspace\src\usbipd\usbipd_import.c:108:[recv_request_import] import request busid 1-209: complete usbip: info: recv_pdu: request 0x8003: complete

ghost commented 4 years ago

@Marietto2008 Glad to see your problem is solved. so did you get your kinectic device working properly in WSL 2? I mean with USB/IP

Marietto2008 commented 4 years ago

no,it's not solved. It's only at the beginning. Now I need to find the way to enable the kinect in linux

Marietto2008 commented 4 years ago

I have a bad news for the moment, @thedozo. check below.

root@DESKTOP-N9UN2H3:~/Desktop# sudo ./libfreenect2/build/bin/Protonect Version: 0.2.0 Environment variables: LOGFILE= Usage: ./libfreenect2/build/bin/Protonect [-gpu=] [gl | cl | clkde | cuda | cudakde | cpu] [] [-noviewer] [-norgb | -nodepth] [-help] [-version] [-frames ] To pause and unpause: pkill -USR1 Protonect [Info] [Freenect2Impl] enumerating devices... [Info] [Freenect2Impl] 2 usb devices connected [Info] [Freenect2Impl] found 0 devices no device connected!

ghost commented 4 years ago

@Marietto2008 seems like you have same problem as me. usb/ip can attach device, but not be detected. I'm also suffering with it.

Marietto2008 commented 4 years ago

read here,what says @swarren :

FWIW, I successfully used a kernel built with this patch applied to run NVIDIA's L4T (Linux4Tegra) flashing tools on an NVIDIA Jetson Xavier that was exported from my native Linux machine. It works pretty nicely; just a bit slower than native. Next, I might investigate whether https://github.com/cezuni/usbip-win works to export a USB device attached to the WSL host into WSL.

it seems that he has been able to do that !

Marietto2008 commented 4 years ago

the solution is here, @thedozo

https://github.com/microsoft/WSL2-Linux-Kernel/pull/45/commits/712f6eab4bf00ff66eba66815dbbd4447a4452e5

Marietto2008 commented 4 years ago

@thedozo : I think that there is a way to do that with the last windows updates,vers. 19619,with the passthrough,the usb devices can be passed from windows to linux / wsl2.

sudip-mondal-2002 commented 2 years ago

image My usb device is passed to wsl2 ubuntu20.04 but can't be detected by apps

please help