Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

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

March 17, 2023 Hyper-VLinuxWindows 10Windows 11

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
1
Facebook Twitter Google + Pinterest
previous post
Print Screen Key Not Working in Windows
next post
Exchange Offline Address Book Not Updating in Outlook

Related Reading

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

How to Increase Size of Disk Partition in...

October 5, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

Installing Language Pack in Windows 10/11 with PowerShell

September 15, 2023

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Hyper-V Virtual Machine Stuck in Stopping/Starting State
  • How to Install Windows 11 on a Hyper-V Virtual Machine
  • How to Install and Configure Free Hyper-V Server 2019/2016
  • Poor Network Performance on Hyper-V VMs in Windows Server 2019
  • Windows Cannot Find the Microsoft Software License Terms
  • Configure SR-IOV for Hyper-V Virtual Machines on Windows Server
  • Managing Hyper-V Virtual Machines with PowerShell
Footer Logo

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


Back To Top