
在今天的教程中,我們將教你如何在Windows Subsystem for Linux 2(WSL2)中使用USB設備。我們將首先安裝必要的工具,然後配置udev以允許非root用戶訪問設備,最後使用USB/IP來連接設備。
先決條件
- WSL2內核版本>=5.10.60.1
可以運行
uname -a
命令確認你的WSL版本。
第一步:安裝usbipd-win
usbipd-win 是一個在Windows上共享USB設備給其他機器,包括Hyper-V和WSL 2的軟體。
安裝usbipd-win需要Microsoft Windows 8.1 x64 / Microsoft Windows Server 2012 或更新版本的Windows系統。
你可以從這裡下載最新的.msi安裝程序,然後在你的USB設備連接的Windows機器上運行它。或者,你也可以使用Windows包管理器安裝:
winget install usbipd
這將會安裝:
- 一個名為
usbipd
的服務(顯示名稱:USBIP設備主機)。 你可以使用Windows的服務應用檢查這個服務的狀態。 - 一個命令行工具
usbipd
。 這個工具的位置將會被添加到PATH
環境變數中。 - 一個名為
usbipd
的防火牆規則,允許所有本地子網連接到這個服務。 你可以修改這個防火牆規則來調整訪問控制。
第二步:安裝USB/IP客戶端工具
我們首先在WSL內安裝USB/IP的用戶空間工具和USB硬體標識符的資料庫。在Ubuntu 20.04 LTS上,運行以下命令:
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
這些指令可能隨著軟體的更新而改變。請確保始終使用最新的指令。
第三步:配置udev
你可能需要配置udev規則以允許非root用戶訪問設備。請在連接設備之前完成此步驟。
以使用openocd和嵌入式設備為例,你需要將share/openocd/contrib/60-openocd.rules文件複製到/etc/udev/rules.d文件夾。
第四步:使用WSL快捷命令
確保你的WSL命令提示符是開啟的。這可以保持WSL 2的輕量級虛擬機活動。然後,你可以使用usbipd的WSL便利命令來連接設備。
首先,運行 usbipd wsl list
列出所有連接到Windows的USB設備。
然後,選擇你想要連接的設備,並運行 usbipd wsl attach --busid
命令。(需要管理員許可權)
在WSL內部,你可以運行 lsusb
來查看已連接的USB設備。
最後,你可以使用 usbipd wsl detach --busid
命令來停止設備共享。
就是這樣!你現在應該能夠在WSL2中使用你的USB設備了。
本文鏈接: https://linuxstory.org/connecting-usb-devices-to-wsl2-a-step-by-step-tutorial
LinuxStory 原創教程,轉載請註明出處,否則必究相關責任。
rykxr5
jr6rr3
Hi,
I wanted to see if you’d be interested in a link exchange for mutual SEO benefits. I can link to your site (linuxstory.org) from a few of our high-authority websites. In return, you would link back to our clients』 sites, which cover niches like health, business services, real estate, consumer electronics, and more.
If you’re interested, let me know — I’d be happy to share more details!
Thanks for your time,
Karen
SEO Account Manager
Hi there
I am looking to help a couple of local businesses increase their monthly revenue by atleast 20% by optimizing the site for more traffic & enquiries.
The best part? You don’t have to spend anything on ads or even pay me.
I am doing this to provide upfront value to local businesses in hopes they will become paying clients one day.
If you wanna apply for this offer, reply to this email!