Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ネットワーク経由でUSB共有

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

 ネットワーク経由でUSB共有

Avatar for Kenichiro MATOHARA

Kenichiro MATOHARA

January 31, 2021
Tweet

More Decks by Kenichiro MATOHARA

Other Decks in Technology

Transcript

  1. / $ apt --color moo moo 2>/dev/null | sed -e

    's/Have you mooed today?/Happy MOO Year!/' 2 / 34
  2. / 最近の発表 最近の発表 「 」 2020-12-26 「 」 2021-01-09 「

    2021-01-23 誰でもファイルアップロード 鹿児島Linux勉強会 2020.12(オン ライン開催) VeraCryptをzuluCryptで 小江戸らぐ 1月のオフな集まり(第222 回) Bitbar/SwiftBarをLinuxでも使いたい」 東海道らぐ あひる焼きさ んのライトニングトークダービー! 4 / 34
  3. / 正攻法 正攻法 端末買い替え USB portを増設 PCI Express/PC Card/Express Card

    懐が寂しい&増設できないマシン(◞‸◟) 6 / 34
  4. / Config Config $ grep -i usbip /boot/config-`uname -r` CONFIG_USBIP_CORE=m

    CONFIG_USBIP_VHCI_HCD=m CONFIG_USBIP_VHCI_HC_PORTS=15 CONFIG_USBIP_VHCI_NR_HCS=8 CONFIG_USBIP_HOST=m CONFIG_USBIP_VUDC=m # CONFIG_USBIP_DEBUG is not set 11 / 34
  5. / 導入 導入 Debian sid amd64/Raspberry Pi OS armhf(buster) Ubuntu

    21.04 Hirsute Hippo (development branch) amd64  $ sudo apt install usbip $ sudo apt install linux-tools-common Ubuntu 16.04 LTS Xenialはusbip 12 / 34
  6. / ホスト(USBを接続する)側の設定 ホスト(USBを接続する)側の設定 usbipd(8) の EXAMPLES $ man usbipd |

    grep ^EXAMPLES$ -A 12 EXAMPLES server:# modprobe usbip-host server:# usbipd -D - Start usbip daemon. server:# usbip list --local - List driver assignments for usb devices. server:# usbip bind --busid=1-2 - Bind usbip-host.ko to the device of busid 1-2. - A usb device 1-2 is now exportable to other hosts! - Use 'usbip unbind --busid=1-2' when you want to shutdown exporting and use th 13 / 34
  7. / usb host moduleの読み込み usb host moduleの読み込み $ sudo modprobe

    -v usbip_host insmod /lib/modules/5.8.0-36-generic/kernel/drivers/usb/usbip/usbip-core.ko insmod /lib/modules/5.8.0-36-generic/kernel/drivers/usb/usbip/usbip-host.ko 14 / 34
  8. / ローカルマシンのUSBデバイス ローカルマシンのUSBデバイス を確認 を確認 今回は busid 1-1.1 の Webcam

    を共有したい busidを指定してbind $ usbip list -l - busid 1-1.1 (046d:0825) Logitech, Inc. : Webcam C270 (046d:0825) - busid 1-1.4 (0a5c:217f) Broadcom Corp. : BCM2045B (BDC-2.1) (0a5c:217f) - busid 1-1.5.3 (2109:0715) VIA Labs, Inc. : VL817 SATA Adaptor (2109:0715) $ sudo usbip bind -b 1-1.1 usbip: info: bind device on busid 1-1.1: complete $ ls -A /sys/bus/usb/drivers/usbip-host 1-1.1 bind match_busid module rebind uevent unbind $ cat /sys/bus/usb/drivers/usbip-host/match_busid 1-1.1 16 / 34
  9. / クライアント(USB機器を利用す クライアント(USB機器を利用す る)側の設定 る)側の設定 usbip(8)のEXAMPLES $ man usbip |

    grep ^EXAMPLES$ -A 10 EXAMPLES client:# usbip list --remote=server - List devices exported by remote server. client:# modprobe vhci-hcd client:# usbip attach --remote=server --busid=1-2 - Connect the remote USB device. client:# usbip detach --port=0 - Detach the usb device. 18 / 34
  10. / リモートのデバイスを確認 リモートのデバイスを確認 $ usbip list -r 192.168.1.180 Exportable USB

    devices ====================== - 192.168.1.180 1-1.1: Logitech, Inc. : Webcam C270 (046d:0825) : /sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.1 : Miscellaneous Device / ? / Interface Association (ef/02/01) 19 / 34
  11. / attachしたデバイスの確認 attachしたデバイスの確認 $ usbip port Imported USB devices ====================

    libusbip: error: fopen libusbip: error: read_record Port 00: <Port in Use> at High Speed(480Mbps) Logitech, Inc. : Webcam C270 (046d:0825) 5-1 -> unknown host, remote port and remote busid -> remote bus/dev 001/018 $ sudo usbip port Imported USB devices ==================== Port 00: <Port in Use> at High Speed(480Mbps) Logitech, Inc. : Webcam C270 (046d:0825) 5-1 -> usbip://192.168.1.180:3240/1-1.1 -> remote bus/dev 001/018 $ ls -A /sys/bus/platform/drivers/vhci_hcd/vhci_hcd.0 attach driver modalias power status.1 status.3 status.5 status.7 u detach driver_override nports status status.2 status.4 status.6 subsystem u $ cat /sys/bus/platform/drivers/vhci_hcd/vhci_hcd.0/status h b t t d d kfd l l b id 22 / 34
  12. / dmesg dmesg $ sudo dmesg : [354830.095734] usb 5-1:

    SetAddress Request (5) to port 0 [354830.332251] usb 5-1: New USB device found, idVendor=046d, idProduct=0825, bcdDevi [354830.332254] usb 5-1: New USB device strings: Mfr=0, Product=0, SerialNumber=2 [354830.332256] usb 5-1: SerialNumber: 7680CBD0 [354830.333594] uvcvideo: Found UVC 1.00 device <unnamed> (046d:0825) [354830.446675] usb 5-1: set resolution quirk: cval->res = 384 23 / 34
  13. / クライアント側の切断操作 クライアント側の切断操作 リモートUSBデバイスを切断. <port> は usbip port かattach時のdmesg を確認する.

    moduleの開放 $ sudo usbip detach -p 00 usbip: info: Port 0 is now detached! $ sudo rmmod -v vhci_hcd usbip_core 26 / 34
  14. / サーバ側の切断操作 サーバ側の切断操作 アンバインド daemonをkill moduleの開放 $ sudo usbip unbind

    -b 1-1.1 usbip: info: unbind device on busid 1-1.1: complete $ pgrep usbipd 1904196 $ sudo killall usbipd $ pgrep usbipd $ lsmod | grep usbip usbip_host 36864 0 usbip_core 40960 1 usbip_host $ sudo rmmod -v usbip_host usbip_core 27 / 34
  15. / 問題 問題 vhci_hcdがデバッグぽい大量のログを吐く Raspberry Pi OS armhfで共有したデバイスをリモートマシンから利 用できない? リモートのデバイスを利用することは可能

    kernelなど色々いじっている環境なので標準環境で再度確認予定 → その後初期状態から試したら問題なかった $ sudo dmesg | pee "wc -l" "grep vhci_hcd | wc -l" 3146 2984 30 / 34
  16. / Raspberry Pi OSで共有したデバイスが見えない $ usbip list -r 10.42.0.253 usbip:

    error: Exported Device List Request failed - Request Completed Successfully usbip: error: failed to get device list from 10.42.0.253 $ usbip --debug list -r 10.42.0.253 2>&1 | grep -v 'usbip: debug: names.c:' usbip: debug: usbip.c:129:[run_command] running command: `list' usbip: debug: usbip_list.c:138:[list_exported_devices] connected to 10.42.0.253:3240 usbip: debug: usbip_network.c:171:[usbip_net_recv_op_common] usbip_net_recv failed: - usbip: error: Exported Device List Request failed - Request Completed Successfully usbip: error: failed to get device list from 10.42.0.253 $ sudo usbip --debug list -r 10.42.0.253 -b 1-1.3 2>&1 | grep -v 'usbip: debug: names usbip: debug: usbip.c:129:[run_command] running command: `list' usbip: debug: usbip_list.c:138:[list_exported_devices] connected to 10.42.0.253:3240 usbip: debug: usbip_network.c:171:[usbip_net_recv_op_common] usbip_net_recv failed: - usbip: error: Exported Device List Request failed - Request Completed Successfully usbip: error: failed to get device list from 10.42.0.253 $ usbip port Imported USB devices $ usbip list -r localhost usbip: error: Exported Device List Request failed - Unknown Op Common Status usbip: error: failed to get device list from localhost 31 / 34
  17. / 奥付 奥付 発表 2021-01-30(sun) 発表者 スライド元Wiki ライセンス CC BY-NC-SA

    4.0 鹿児島Linux勉強会 2021.01(オンライン開催) Kenichiro Matohara(matoken) https://wiki.matoken.org/linux/usbip 34 / 34