LightBlog

mardi 9 novembre 2021

You can now connect USB devices in Windows Subsystem for Linux under Windows 11

Microsoft introduced Windows Subsystem for Linux (WSL) a while back, which brought support for running Linux apps straight from your Windows installation. Being such a complex compatibility layer, WSL had some limitations. The initial implementation didn’t even use a full-fledged Linux kernel, so several applications faced compatibility issues. Version 2 made a lot of improvements, but something was still missing: Support for connecting physical USB devices.

If you’re an active user of Windows Subsystem for Linux and want to access USB devices right from the Linux instance running under WSL, then you’ll be happy to know that there has been a significant progress in this front. Thanks to Microsoft’s contributions to the open-source usbipd-win project, you can now enjoy USB passthrough access in WSL. It means end users can perform tasks like flashing Android devices under Windows Subsystem for Linux, which are otherwise not supported by the Linux subsystem.

What is usbipd-win?

The usbipd-win project is all about creating a solution for sharing locally connected USB devices to other machines, including Hyper-V guests and WSL2. However, the official WSL2 Linux kernel used to lack support for the USB/IP protocol, requiring users to build the kernel themselves.

Since WSL kernel version 5.10.60.1, the required parameters are configured out of the box, so no manual recompilation is needed. Microsoft has also contributed a command line interface to the project to both enable a USB device for sharing on Windows and seamlessly attach it from within WSL.

Connect USB devices under Windows Subsystem for Linux

Before starting, make sure that you’re running Windows 11 and have installed all WSL updates. As mentioned earlier, you need a WSL 2 Linux distro for this to work.

  1. Run the following command from within WSL:
    uname -a

    It should report a kernel version of 5.10.60.1 or later, as shown below:
    WSL Ubuntu kernel version

  2. Head over the GitHub repo of the usbipd-win project. Then download and install the latest release.
    • The latest version of usbipd-win supports silent driver installation, thanks to the Windows Hardware Compatibility Program certified drivers. It also supports Dev channel builds of Windows 11.
    • In addition to the release page on GitHub, you can install and update the app using Windows Package Manager CLI (AKA winget).
      winget install --interactive --exact dorssel.usbipd-win
  3. Install the user space tools for USB/IP and a database of USB hardware identifiers. If you’re running Ubuntu on WSL, execute the following command:
    sudo apt install linux-tools-5.4.0-77-generic hwdata
    • For other distros, consult the documentation of the relevant package management tool.
  4. Now we need to modify the sudo options to allow the root user to find the usbip command. To do so, edit the /etc/sudoers file using sudo visudo and add /usr/lib/linux-tools/5.4.0-77-generic to the beginning of secure_path. It should look like the following:
    Defaults        secure_path="/usr/lib/linux-tools/5.4.0-77-generic:/usr/local/sbin:..."

    WSL Ubuntu sudores usbip

  5. Open a new Terminal instance as Administrator and type the following command to list all the USB devices connected to Windows.
    usbipd wsl list

    usbipd wsl list

  6. Note down the BUSID value of the USB device you want to attach to WSL. Next, run the following command to initiate the attachment process. You’ll be prompted by WSL for a password to run a sudo command.
    usbipd wsl attach --busid <busid>

    For example, here we’re attaching an Android device’s Fastboot interface to WSL from the host Windows 11 instance:
    usbipd wsl attach device

  7. Now open a new WSL 2 instance and run the lsusb command to see available USB devices. It should list the attached device(s).
    usbipd wsl Ubuntu lsusb
  8. That’s it! You can now work with your USB device right from WSL.
    usbipd wsl Ubuntu fastboot

When you’re done, you can detach the device using the command shown below. Once again, run it from a Terminal instance running as administrator.

usbipd wsl detach --busid <busid>

To learn more, take a look at the official announcement and usbipd-win’s GitHub Wiki section.


Thanks to XDA Senior Member Some_Random_Username for the tip!

The post You can now connect USB devices in Windows Subsystem for Linux under Windows 11 appeared first on xda-developers.



from xda-developers https://ift.tt/3bVM59F
via IFTTT

Aucun commentaire:

Enregistrer un commentaire