WSL icon indicating copy to clipboard operation
WSL copied to clipboard

[WSL 2] Attaching an USB device

Open ghost opened this issue 6 years ago • 114 comments

I want to attach an USB device (iPhone) with WSL, how to accomplish that? USB device is connected with Windows host. I'm using kernel 4.19.104 and enabled USB support manually by compiling it from source.

Any suggestions regarding above mentioned issues?

ghost avatar Apr 30 '20 13:04 ghost

WSL 2 operates in a lightweight VM and does not have USB pass-through access.

Even if enabled in the Linux kernel, that is still simply inside the VM.

This is a duplicate of #689.

sirredbeard avatar Apr 30 '20 20:04 sirredbeard

Even if enabled in the Linux kernel, that is still simply inside the VM.

Nope, it "was" somehow possible. See this pull request https://github.com/microsoft/WSL2-Linux-Kernel/pull/45. I tried it once but the compiled kernel did not boot WSL2 VM, maybe I did something wrong.

Biswa96 avatar Apr 30 '20 21:04 Biswa96

WSL 2 operates in a lightweight VM and does not have USB pass-through access.

Even if enabled in the Linux kernel, that is still simply inside the VM.

This is a duplicate of #689.

@sirredbeard so for now there’s no way to attach USB devices into WSL?

ghost avatar Apr 30 '20 21:04 ghost

Generally yes.

There are hacks that use USB over IP but they aren't supported and YMMV.

sirredbeard avatar Apr 30 '20 21:04 sirredbeard

Even if enabled in the Linux kernel, that is still simply inside the VM.

Nope, it "was" somehow possible. See this pull request microsoft/WSL2-Linux-Kernel#45. I tried it once but the compiled kernel did not boot WSL2 VM, maybe I did something wrong.

Also tried by me. But usbip can’t attach usb devices with WSL. I’m already having a long discussion here- https://github.com/cezanne/usbip-win/issues/149

ghost avatar Apr 30 '20 21:04 ghost

Generally yes.

There are hacks that use USB over IP but they aren't supported and YMMV.

Bad news.

ghost avatar Apr 30 '20 21:04 ghost

My issue is solved with USB/IP tool from this repo: https://github.com/cezanne/usbip-win I have compiled kernel 4.19.104 with USB modules and now I can attach USB devices with WSL using USB/IP. My solution goes like this: https://github.com/cezanne/usbip-win/issues/149#issuecomment-622367314

ghost avatar May 01 '20 12:05 ghost

I tried to attach the kinect,using usbip and this is what happened :

root@DESKTOP-N9UN2H3:~/Desktop# sudo ./libfreenect2/build/bin/Protonect Version: 0.2.0 Environment variables: LOGFILE=<protonect.log> 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!

Marietto2008 avatar May 03 '20 18:05 Marietto2008

@sirredbeard Any news about the support in default build?

flokixdev avatar Jun 07 '20 08:06 flokixdev

My issue is solved with USB/IP tool from this repo: https://github.com/cezanne/usbip-win I have compiled kernel 4.19.104 [...]

I'm glad it worked for you, but I personally do not think that USB support in WSL2 should require recompiling a custom Linux kernel and installing a prerelease of a Windows kernel driver. This feature should just work out of the box.

mtrojnar avatar Jun 11 '20 10:06 mtrojnar

I wanted to follow up with this and see if there has been any news of this feature coming by default?

ghost avatar Jun 28 '20 01:06 ghost

After getting Steam for Linux installed in Ubuntu On Windows, i am interested in this feature request or limitation of WSL2 as well.

Could not help thinking of VirtualHere but have only used android server with non linux clients (mostly remote cloud gaming VMs like Paperspace and Shadow running windows or windows server) and can see VirtualHere has CLI for linux clients at https://www.virtualhere.com/node/955.

Yeah YMMV but am sure a custom kernel and VH can help out for many end user case scenarios in WSL.

Balderick avatar Jun 28 '20 02:06 Balderick

The issue is not resolved by usbip because when you install the windows part you have to remove protection, test signature. This could be an attack vector on your machine and could not be accepted on work computer, So we need to have some internal tools to be able to do that. If USB-IP is working correctly why we don't have it available directly by Windows when se enable some additional tools ?

jbdamiano avatar Jun 30 '20 05:06 jbdamiano

The issue is not resolved by usbip

Well, it would be addressed by USB/IP if USB/IP kernel code was merged into the Microsoft's WSL2 kernel. But you are right, this issue is not fixed and it should not be closed.

mtrojnar avatar Jun 30 '20 09:06 mtrojnar

Not only the USP/IP kernel code, wee need to have the USP/IP Windows driver available and signed by microsoft to avoid to do: bcdedit.exe /set TESTSIGNING ON because this in not safe as you have to disable the UEFI secure boot to do that.

jbdamiano avatar Jun 30 '20 09:06 jbdamiano

the problem is deeper,since actually on WSL2 there is no official passthrough for the multimedias USB devices.

Marietto2008 avatar Jun 30 '20 09:06 Marietto2008

But the problem can be fixed with this solution :

onomatopellan commented on 6 May

I found it very easy to use. It's free if you connect 1 device and you use the gui linux version as client.

For the server, just download and run it: https://www.virtualhere.com/sites/default/files/usbserver/vhusbdwin64.exe

For the client (you need an XServer and gtk2):

wget https://www.virtualhere.com/sites/default/files/usbclient/vhuit64 chmod 777 vhuit64 sudo ./vhuit64

After that you can right click -> "Specify the hub" and add YOUR_PC_IP:7575 right click on a device -> Use this device

And that's it. You should see the device with lsusb.

Marietto2008 avatar Jun 30 '20 09:06 Marietto2008

wget https://www.virtualhere.com/sites/default/files/usbclient/vhuit64 chmod 777 vhuit64 sudo ./vhuit64

modprobe: FATAL: Module vhci-hcd not found in directory /lib/modules/4.19.104-microsoft-standard

mtrojnar avatar Jul 02 '20 12:07 mtrojnar

you should recompile the kernel and u should activate a lot of parameters related to usb. its better if u don't choose to load as modules.but built into the kernel.

Marietto2008 avatar Jul 02 '20 12:07 Marietto2008

you should recompile the kernel and u should activate a lot of parameters related to usb. its better if u don't choose to load as modules.but built into the kernel.

Rebuilding the WSL2 kernel from sources may work, but functionality as basic as USB support should not require it.

mtrojnar avatar Jul 02 '20 20:07 mtrojnar