dockur / windows

Windows inside a Docker container.
MIT License
29.21k stars 1.99k forks source link

USB Device Passthrough does not show up in Windows 11 #272

Closed teije closed 8 months ago

teije commented 8 months ago

I have attempted to passthrough a USB connected ESP32.

TL:DR; As far as I understand I have correctly executed all steps already described in Issue #140, but no luck so far.

Does anyone have any tips on how to get this to work?

Steps taken so far:

I have identified it to be device on: Bus003 Device005 with the vendorid:productid being: 1a86:55d4

  1. When I run lsusb on the Unraid host machine I get:

    Bus 004 Device 002: ID 090c:1000 Silicon Motion, Inc. - Taiwan (formerly Feiya Technology Corp.) Flash Drive
    Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    > Bus 003 Device 005: ID 1a86:55d4 QinHeng Electronics USB Single Serial
    Bus 003 Device 004: ID 051d:0002 American Power Conversion Uninterruptible Power Supply
    Bus 003 Device 003: ID 1a40:0101 Terminus Technology Inc. Hub
    Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 001 Device 004: ID 8087:0029 Intel Corp. AX200 Bluetooth
    Bus 001 Device 002: ID 048d:8297 Integrated Technology Express, Inc. IT8297 RGB LED Controller
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
  2. When I run lsusb on the 'WindowsinDocker'-container I get: (Should the container be able to see these devices? I read something about being in priviledged mode, I am not quite sure what this is, I did run this lsusb command with sudo)

    Bus 001 Device 001: ID 1d6b:0002 Linux 6.1.74-Unraid xhci-hcd xHCI Host Controller
    Bus 001 Device 002: ID 048d:8297 ITE Tech. Inc. ITE Device(8595)
    Bus 001 Device 004: ID 8087:0029  
    Bus 002 Device 001: ID 1d6b:0003 Linux 6.1.74-Unraid xhci-hcd xHCI Host Controller
    Bus 003 Device 001: ID 1d6b:0002 Linux 6.1.74-Unraid xhci-hcd xHCI Host Controller
    Bus 003 Device 003: ID 1a40:0101  USB 2.0 Hub
    Bus 003 Device 004: ID 051d:0002 American Power Conversion Back-UPS BX950MI  FW:295202G -302202G 
    > Bus 003 Device 005: ID 1a86:55d4  USB Single Serial
    Bus 004 Device 001: ID 1d6b:0003 Linux 6.1.74-Unraid xhci-hcd xHCI Host Controller
    Bus 004 Device 002: ID 090c:1000 Samsung Flash Drive FIT 
  3. I have attempted to use the /dev/bus/usb/bus-id/device-id ARGUMENTS configuration: -device usb-host,hostdevice=/dev/bus/usb/003/005 afbeelding

    • This configfuration prevents the container from starting ❯ ERROR: qemu-system-x86_64: -device usb-host,hostdevice=/dev/bus/usb/003/005: failed to open /dev/bus/usb/003/005: No such file or directory
    • Screenshot: afbeelding
  4. I have attempted to use the vendorid:productid ARGUMENTS configuration: -device usb-host,vendorid=0x1a86,productid=0x55d4 afbeelding

    • This configuration allows the container to start, which seemed hopeful at first, but I don't think the device is actually properly passedthrough.
    • Below is a screenshot of what I can see in USBDeview installed on the Windows11 installation inside the docker container
    • I am unsure of what the Port#0005.Hub#0001-device is, but I do not think that it is the ESP32.
      Port_#0005.Hub_#0001    USB Input Device    HID (Human Interface Device)    Yes Yes No  No      28754-0000:00:02.0-1    3/13/2024 8:00:07 PM    3/12/2024 9:19:39 AM    0627    0001    0.00        03  00  00      DOCKERW-J5V62GK         6&25ad3554&0    HidUsb  @input.inf,%HID.SvcDesc%;Microsoft HID Class Driver hidusb.sys      (Standard system devices)       100 mA  2.00    USB Input Device    10.0.22621.2506 HID_Inst.NT input.inf   USB\VID_0627&PID_0001\28754-0000:00:02.0-1  Removable, UniqueID, SurpriseRemovalOK  3/12/2024 9:19:39 AM    3/12/2024 9:19:39 AM    3/13/2024 8:00:07 PM    

      afbeelding

kroese commented 8 months ago

From all your steps it looks like you did everything correctly, so I do not have any good explanation why it doesn't work in your case :(

teije commented 8 months ago

Thanks for your quick response!

Too bad you have no further insights. Perhaps if I get a better understanding of how passthrough is done, from Unraid -> Docker container -> Windows, I can narrow down the problem.

Could you explain how I can determine if the device is properly passed through to the docker container?

And could you explain how I can see how the Docker container forwards the passthrough to the Windows VM?

avoiceofreason commented 8 months ago

I have successfully used USB passthrough, although not on Unraid

your ARGUMENTS environment variable should look like this:

-e ARGUMENTS="-device usb-host,vendorid=0x1a86,productid=0x55d4"

Also make sure you are passing through the host usb device:

--device=/dev/bus/usb

I have also managed to passthrough a usb port, rather than a specific device using:

-e ARGUMENTS="-usb -device usb-host,hostbus=1,hostport=1.3"

[You need to do an lsusb -t to work out the host bus and host port numbers]

You might want to try passing through a simple memory stick that Windows has drivers for to make sure its working and then try the ESP. I think you need drivers for the USB >> UART on most ESP boards.But remember each USB device has its own vendor/product IDs

teije commented 8 months ago

@avoiceofreason: thank you so much! My ESP32 is now detected!

Adding the usb as device as shown (in addition to the existing ARGUMENTS variable) in this screenshot:

image

One downside is that upon reboot the bus-id and device-id might change, which breaks the usb mapping. This is easy to spot, because the container will fail to start when this is the case.

@kroese: You talk about this issue in your FAQ, but there the suggestion is to set ARGUMENTS to use the vendorid and productid, which I already am. Do you hapen to know how I can rework this device mapping to one that is based on vendorid and productid?

Anyways; now that it got detected properly I was able to flash the ESP32, but the serial monitor did not output anything:

Flashing OK image

This comment helped me get the proper serial monitor output:

https://community.platformio.org/t/cant-get-output-from-serial-monitor/15533/19

avoiceofreason commented 8 months ago

In theory passing these 2 lines in combination should always find the same usb device every boot:

-e ARGUMENTS="-device usb-host,vendorid=0x1a86,productid=0x55d4" --device=/dev/bus/usb

While these 2 lines would always find USB bus 1 and port 1.3:

-e ARGUMENTS="-usb -device usb-host,hostbus=1,hostport=1.3" --device=/dev/bus/usb

This does work on Ubuntu, so maybe its a Unraid thing...

teije commented 8 months ago

Should I leave out the port and device number from the /dev/bus/usb line? That might be where my error is located.

teije commented 8 months ago

Small update: I have changed the /dev/bus/usb/003/004 bit in the Unraid device section to /dev/bus/usb. This works and seems to not break when the id's change!

Thanks @kroese & @avoiceofreason ! As far as I can see now, the passthrough of the ESP32 works good now!

teije commented 8 months ago

@kroese: Maybe it is useful to update de FAQ with a concise version of @avoiceofreason 's solution to my USB passthrough issue? This issue sounds like it might apply to more people than just me, it sounding like a fairly generic issue.

kroese commented 8 months ago

@teije I dont see any difference between what @avoiceofreason proposed and what was already in the Readme? It tells you to include /dev/bus/usb in the compose file, and the line with the pid/vid is also the same.

teije commented 8 months ago

@kroese : You are right, upon reading the FAQ again I release that I should have rtfm a bit better. Once again thanks for the help and effort you put into this project!