The environment is
- Windows 10
- WSL2 Ubuntu 20.04 LTS
- Mount USB to WSL
- Setup usbipd-win
- Connect USB device to WSL
- Hack to connect the desired device to WSL without Admin privilege
Mount USB to WSL
It’s easy to mount if it is just a USB drive that is shown on Windows e.g.
Let’s create a directory to mount the USB directory first. Then, mount it.
sudo mkdir /mnt/usb sudo mount -t drvfs E: /mnt/usb
If you execute the following command, you can see the files on the USB stick.
ls -la /mnt/usb
Execute the following command if you want to umount it.
sudo unmount /mnt/usb
Install usbipd-win to the Windows machine
First, usbipd-win needs to be installed on your host machine before doing something on WSL.
- Go to the release page of usbipd-win
- Download msi and install it
You can see the following service after the installation.
> sc queryex usbipd SERVICE_NAME: usbipd TYPE : 10 WIN32_OWN_PROCESS STATE : 4 RUNNING (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN) WIN32_EXIT_CODE : 0 (0x0) SERVICE_EXIT_CODE : 0 (0x0) CHECKPOINT : 0x0 WAIT_HINT : 0x0 PID : 2032 FLAGS
Preparation on WSL with Ubuntu
Execute the following command to install the necessary tools on WSL.
sudo apt update 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
If you don’t update the package list by
apt update, you could get the following error
$ sudo apt install linux-tools-virtual hwdata [sudo] password for yuto: Reading package lists... Done Building dependency tree Reading state information... Done The following package was automatically installed and is no longer required: libfwupdplugin1 Use 'sudo apt autoremove' to remove it. The following additional packages will be installed: libdw1 linux-tools-5.4.0-125 linux-tools-5.4.0-125-generic linux-tools-common The following NEW packages will be installed: hwdata libdw1 linux-tools-5.4.0-125 linux-tools-5.4.0-125-generic linux-tools-common linux-tools-virtual 0 upgraded, 6 newly installed, 0 to remove and 0 not upgraded. Need to get 6026 kB of archives. After this operation, 27.9 MB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://archive.ubuntu.com/ubuntu focal/main amd64 hwdata all 0.333-1 [23.3 kB] Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 libdw1 amd64 0.176-1.1build1 [226 kB] Get:3 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-tools-common all 5.4.0-125.141 [187 kB] Get:4 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-tools-5.4.0-125 amd64 5.4.0-125.141 [5586 kB] Get:5 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-tools-5.4.0-125-generic amd64 5.4.0-125.141 [1996 B] Ign:6 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 linux-tools-virtual amd64 22.214.171.124.126 Err:6 http://security.ubuntu.com/ubuntu focal-updates/main amd64 linux-tools-virtual amd64 126.96.36.199.126 404 Not Found [IP: 188.8.131.52 80] Fetched 6024 kB in 1s (4058 kB/s) E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/l/linux-meta/linux-tools-virtual_184.108.40.206.126_amd64.deb 404 Not Found [IP: 220.127.116.11 80] E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
Connect USB device to WSL
All commands in this section are on the host machine.
Check the device list
Let’s check how many devices are there and which one is what we want to connect.
> usbipd.exe wsl list BUSID VID:PID DEVICE STATE 1-5 0b0e:245e Jabra Link 370, USB Input Device Not attached 1-7 0408:5390 HP Full-HD Camera, HP IR Camera Not attached 1-8 06cb:00b7 Synaptics VFS7552 Touch Fingerprint Sensor with PurePrint... Not attached 1-14 8087:0029 Intel(R) Wireless Bluetooth(R) Not attached 2-1 8087:0af1 HP GNSS Sensor Not attached 2-2 8087:0aca USB Serial Device (COM5), USB Serial Device (COM4), Modem... Not attached 2-3 8087:0ac9 Intel(R) XMM(TM) 7360 LTE-A Not attached 6-2 05e0:1200 USB Input Device Not attached 6-5 2109:8888 USB Billboard Device Not attached 7-3 0bda:8153 Realtek USB GbE Family Controller Not attached 9-1 0c45:7638 USB Input Device Not attached 9-5 03f0:0269 HP Thunderbolt Dock Audio Headset, USB Input Device Not attached 9-7 03f0:0667 WinUSB, USB Input Device Not attached 10-1 2149:2306 USB Input Device Not attached
In my case, 6-2 is what I want. It’s a scanner.
Attach the desired device to WSL
But I got this error.
> usbipd.exe wsl attach --busid 6-2 usbipd: info: Using default WSL distribution 'Ubuntu-20.04'; specify the '--distribution' option to select a different one. usbipd: error: Access denied; this operation requires administrator privileges. usbipd: info: The first time attaching a device to WSL requires elevated privileges; subsequent attaches will succeed with standard user privileges.
I got the following error if I executed it with an Admin user.
> usbipd.exe wsl attach --busid 6-2 usbipd: error: There are no WSL distributions installed; see https://docs.microsoft.com/windows/wsl/basic-commands#install on how to install one.
Because I installed WSL on my own user but not on the Admin user. The Admin user doesn’t have WSL.
In this case, you can’t execute the command even if you try the following command. The domain name and user name are replaced with a placeholder here.
> runas /profile /user:<Domain name>\<User Name> "usbipd.exe wsl attach --busid 6-2" Enter the password for <Domain name>\<User Name>: Attempting to start usbipd.exe wsl attach --busid 6-2 as user "<Domain name>\<User Name>" ...
This command fails. A new window appears but is closed immediately.
usbipd: warning: A third-party firewall may be blocking the connection; ensure TCP port 3240 is allowed.
The account must be in the Administrator group. I executed the following command after putting my account into the Administrator group.
> usbipd.exe wsl attach --busid <busid> usbipd: info: Using default WSL distribution 'Ubuntu-20.04'; specify the '--distribution' option to select a different one. usbipd: warning: A third-party firewall may be blocking the connection; ensure TCP port 3240 is allowed. usbip: error: tcp connect usbipd: error: Failed to attach device with busid '6-2'.
But this error above is thrown…
Hmm… I don’t have a right to turn off Firewall. I uninstalled usbipd-win and re-installed it but it didn’t work for me.
Hack to connect the desired device to WSL without Admin privilege
Let’s cheat here. If you connect to the WSL from the host machine via ssh, you can ignore the firewall settings.
Start SSH server on WSL
All commands are on WSL here.
Execute the following command on WSL to check the content of ssh connection config.
Then, you will see the following.
Change it to yes and save it.
Then, execute the following command. The server will start.
$ sudo service ssh restart * Restarting OpenBSD Secure Shell server sshd
Connect to WSL via SSH from the Host machine
The format to connect via SSH is the following.
ssh <username>@<IP address of WSL> -R 3240:127.0.0.1:3240
You can check the IP address on WSL with
ip a command. The IP address is shown on inet for eth0.
$ ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: bond0: <BROADCAST,MULTICAST,MASTER> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 6e:27:82:86:7d:6e brd ff:ff:ff:ff:ff:ff 3: dummy0: <BROADCAST,NOARP> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 56:5a:7d:9f:42:5d brd ff:ff:ff:ff:ff:ff 4: [email protected]: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000 link/ipip 0.0.0.0 brd 0.0.0.0 5: [email protected]: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000 link/sit 0.0.0.0 brd 0.0.0.0 6: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 00:15:5d:1c:7f:e0 brd ff:ff:ff:ff:ff:ff inet 172.23.31.247/20 brd 172.23.31.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::215:5dff:fe1c:7fe0/64 scope link valid_lft forever preferred_lft forever
Let’s connect to the WSL from the host machine via SSH.
> ssh [email protected] -R 3240:127.0.0.1:3240 [email protected]'s password: Welcome to Ubuntu 20.04.5 LTS (GNU/Linux 18.104.22.168-microsoft-standard-WSL2 x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Tue Nov 15 15:58:58 CET 2022 System load: 0.0 Processes: 36 Usage of /: 1.1% of 250.98GB Users logged in: 0 Memory usage: 9% IPv4 address for eth0: 172.23.31.247 Swap usage: 0% => There is 1 zombie process. 0 updates can be applied immediately. The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law.
It could connect to WSL.
Show the available devices and try to connect the device to WSL
I could see the following result when executing the following command on WSL.
$ usbip list -r 127.0.0.1 Exportable USB devices ====================== - 127.0.0.1 1-1: Symbol Technologies : Bar Code Scanner (05e0:1200) : USB\VID_05E0&PID_1200\S/N:38B63F28B0A967459FDC95404F7D3524:3 : (Defined at Interface level) (00/00/00) : 0 - Human Interface Device / Boot Interface Subclass / Keyboard (03/01/01) 6-2: Symbol Technologies : Bar Code Scanner (05e0:1200) : USB\VID_05E0&PID_1200\22222523070578__ : (Defined at Interface level) (00/00/00) : 0 - Human Interface Device / Boot Interface Subclass / Keyboard (03/01/01)
Yes!! No more connection errors here!!
However… it doesn’t work for this scanner at all…
$ usbip attach -b 6-2 -r 127.0.0.1 usbip: error: import device
Oooooops… Lost my day…
According to the wiki page of usbipd-win, some devices can’t be used…