Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Windows 10 / Attaching Host USB Devices to WSL or Hyper-V VM

March 17, 2023

Attaching Host USB Devices to WSL or Hyper-V VM

You can use the open-source usbipd-win project to access a computer’s physical USB devices from the Windows Subsystem for Linux (WSL2) or Hyper-V virtual machine. This tool allows you to pass-through an external USB device connected to the Windows host to any Linux distribution (running as WSL) or to a virtual machine. This allows performing any actions with USB devices from virtual machines or Linux environment (flashing Android devices, using ADB and Fastboot, accessing smart cards, working with Arduino hardware, etc.).

Usbipd-win uses the TCP/IP protocol to forward the USB device traffic over a virtual network interface between the VM/WSL and the host Windows operating system. First, we’ll show how to install the usbipd-win server on a Windows host, then we’ll install a USB/IP client on Linux (WSL) and attach a shared USB device to the Linux VM (WSL).

Usbipd-win supports Windows 8.1 x64 and Windows Server 2012 R2 (and later) and allows to share local USB devices on Windows with other virtual machines (including WSL2 and Linux guest operating systems on Hyper-V). Previously on Hyper-V, it was only possible to redirect USB drives to VMs or other USB device types through the rather limited Enhanced Session Mode.

Usbipd-win project is available on GitHub (https://github.com/dorssel/usbipd-win). You can download and install it manually (an MSI installation file is available), but it’s much quicker to install it using the built-in Winget package manager.

winget install --interactive --exact dorssel.usbipd-win

Install usbipd-win on Windows 10/11

The program will create a separate usbipd (USBIP Device Host) service on Windows: "C:\Program Files\usbipd-win\usbipd.exe" which listens on TCP port 3240

usbipd (USBIP Device Host) service on Windows

An additional rule has been created in Windows Defender Firewall for the usbipd.exe to allow access to TCP port 3240 from computers on the local network.

Now let’s configure USBIP support in Windows Subsystem for the Linux environment. Make sure that the kernel version in your image is at least 5.10.60.1 (our demo example uses WSL 2 with an Ubuntu 22.04 LTS image):

$ uname -a

Now you need to install USB/IP tools and USB hardware ID base.

$ sudo apt install linux-tools-virtual hwdata
$ sudo update-alternatives --install /usr/local/bin/usbip usbip `ls /usr/lib/linux-tools/*/usbip | tail -n1` 20

install usbip on linux

Use the following command in the Debian WSL image:

$ sudo apt-get install usbip hwdata usbutils
Install USB/IP tools in an rpm-based WSL image (CentOS/Oracle Linux):

$ sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
$ sudo rpm -ivh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
$ sudo yum install kmod-usbip
$ sudo yum install usbip-utils
$ sudo yum install hwdata

Now open an elevated command prompt on the host Windows computer and list the USB devices:

usbipd wsl list

As you can see, none of the USB devices are shared (Not shared). You may share the USB device by its BUSID. In my example, I’d like to passthrough the USB Mass Storage Device with BUISID 4-2 into WSL.

usbipd wsl attach --busid 4-2

Attach shared USB device over the IP network to WSL

  • If you are using WSL 1 (not supported by usbip) you will get an error.
    sbipd: error: The specified WSL distribution is using WSL 1, but WSL 2 is required. Learn how to upgrade at https://docs.microsoft.com/windows/wsl/basic-commands#set-wsl-version-to-1-or-2.
  • If an error appears: usbipd: error: WSL kernel is not USBIP capable, update WSL system with the following command:
    wsl --update

Check that your USB flash drive is connected to WSL:

$ dmesg | tail
$ lsusb

lsusb - check for USB device on WSL

If you would like to share your USB device with another computer running Linux over the network (it can be a virtual machine with a Linux guest on Hyper-V or any other hypervisor), first list the available USB devices on a remote Windows host:

$ usbip list --remote=192.168.13.21

You can now mount the required USB device by its ID:

$ sudo usbip attach -remote=192.168.13.21 --busid=4-2

In this example, the IP address of the Windows host on which the usbipd-win server is running is specified.

The shared USB device should now be visible to your Linux tools.

To disable USB device sharing in Windows:

usbipd wsl detach --busid 4-2

Please note that USB drives connected in this way are not recognized as block devices in WSL. Check this using the lsblk command. The fact is that the WSL kernel does not have a driver for USB drives (to add them, you will have to rebuild the kernel).

You will be able to mount the file system of the shared USB drives in the standard way on the Linux distros.

Therefore, you must use the following commands to mount an external USB flash drive, floppy disc, or SD card in WSL:

$ sudo mkdir /mnt/f
$ sudo mount -t drvfs f: /mnt/f

Mount usb flash drive file system in WSL with drvfs

WSL mount FAT, ExFAT, ReFs, or NTFS drives, as well as VHD images.

Thus, usbipd-win can be used to pass-through physical USB devices from a physical Windows host to WSL, virtual machine, or Linux computers over a network using the USBOverIP protocol.

You may also find it useful to read the article on how to move WSL to a different drive.
0 comment
3
Facebook Twitter Google + Pinterest
Hyper-VLinuxWindows 10Windows 11
previous post
Sending an E-mail to a Microsoft Teams Channel
next post
Exchange Offline Address Book Not Updating in Outlook

Related Reading

How to Repair EFI/GPT Bootloader on Windows 10...

March 16, 2024

How to Restore Deleted EFI System Partition in...

March 11, 2024

How to Allow Multiple RDP Sessions on Windows...

March 15, 2024

How to Run Program without Admin Privileges and...

June 8, 2023

Wi-Fi (Internet) Disconnects After Sleep or Hibernation on...

March 15, 2024

How to Install Remote Server Administration Tools (RSAT)...

March 17, 2024

Refresh AD Groups Membership without Reboot/Logoff

March 15, 2024

Network Computers are not Showing Up in Windows...

March 15, 2024

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Hyper-V Virtual Machine Stuck in Stopping/Starting State
  • How to Install and Configure Free Hyper-V Server 2019/2016
  • Poor Network Performance on Hyper-V VMs in Windows Server 2019
  • How to Install Windows 11 on a Hyper-V Virtual Machine
  • Windows Cannot Find the Microsoft Software License Terms
  • How to Assign (Passthrough) a Physical GPU to a Hyper-V Virtual Machine
  • How to Enable and Configure Hyper-V Remote Management
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top