Windows 11 WSL2 USBメモリー接続 - WSL 2 using the USB/IP [WSL]
Windows 11のWSL2で,USB接続ができるようになった。
https://docs.microsoft.com/en-us/windows/wsl/connect-usb
USBメモリーをWSL2のUbuntuにUSB Mass Storage deviceで認識させるまでには,WSL2のLinuxカーネルのビルドが必要だった。
先に使用方法を示す。カーネルビルドなどの準備作業は後述する。
Windows 11
・WSL2のUbuntuを起動する。
・管理者コマンドプロンプトでusbipd wsl コマンドを実行する。
C:\Windows\system32>usbipd wsl list
BUSID DEVICE STATE
3-2 USB 大容量記憶装置 Not shared
5-4 USB ビデオ デバイス Not shared
C:\Windows\system32>usbipd wsl attach -b 3-2
[sudo] cst100 のパスワード:
C:\Windows\system32>usbipd wsl list
BUSID DEVICE STATE
3-1 USB 大容量記憶装置 Attached - Ubuntu
5-4 USB ビデオ デバイス Not attached
BUSID 3-2 をWSLにアタッチする。
WSL2のUbuntu
root@e130:/# dmesg
:
[ 52.956662] usb-storage 1-1:1.0: USB Mass Storage device detected
[ 52.958231] usb-storage 1-1:1.0: Quirks match for vid 090c pid 1000: 400
[ 52.959576] scsi host1: usb-storage 1-1:1.0
[ 54.623429] scsi 1:0:0:0: Direct-Access General USB Flash Disk 1100 PQ: 0 ANSI: 4
[ 54.627153] sd 1:0:0:0: Attached scsi generic sg3 type 0
[ 54.638085] sd 1:0:0:0: [sdd] 31506432 512-byte logical blocks: (16.1 GB/15.0 GiB)
[ 54.647483] sd 1:0:0:0: [sdd] Write Protect is off
[ 54.649784] sd 1:0:0:0: [sdd] Mode Sense: 43 00 00 00
[ 54.657851] sd 1:0:0:0: [sdd] No Caching mode page found
[ 54.658928] sd 1:0:0:0: [sdd] Assuming drive cache: write through
[ 54.725560] sdd: sdd1 sdd2 sdd3
[ 54.733632] sd 1:0:0:0: [sdd] Attached SCSI removable disk
sddとしてusbメモリーが認識されている。
これで,mount /dev/sdd3 /mnt したり,dd of=/dev/sdd ができる。
準備作業
Windows 11に,USBIPD-WINをインストール
こちらからダウンロードしてインストールする。
https://github.com/dorssel/usbipd-win/releases/
usbipd-win 1.20 から usbipd wsl コマンドが使えるようになったっぽい。
WSL2のUbuntuに,usbip をインストール
sudo –s
apt update
apt install linux-tools-5.4.0-77-generic hwdata
visudo
(パスに追加)
Defaults secure_path="/usr/lib/linux-tools/5.4.0-77-generic:/usr/local/sbin:..."
カーネルをビルド(デバイスドライバーのUSB Mass Storage Supportを追加するため)
apt install -y build-essential flex bison libssl-dev libelf-dev pkg-config libncurses-dev dwarves
git clone https://github.com/microsoft/WSL2-Linux-Kernel.git /usr/src/5.10.60.1-microsoft-standard-WSL2
cd /usr/src/5.10.60.1-microsoft-standard-WSL2/
git branch --list --all
git checkout linux-msft-wsl-5.10.y
cp Microsoft/config-wsl .config
make menuconfig
Device Drivers > USB support > <*> USB Mass Storage support
<Save> <Exit>
make -j4
make modules_install
cp vmlinux /mnt/c/wslkernel/vmlinux
Cドライブのwslkernelディレクトリ(任意作成)にvmlinux をコピー(上の囲みの最後)。
Windows でWSL2のカーネルをセットする。ユーザーディレクトリに.wslconfig ファイルを作る
C:\>cd \Users\cst100
C:\Users\cst100>notepad .wslconfig
[wsl2]
kernel=C:\\wslkernel\\vmlinux
区切りを\\(¥¥)とする。
WSLをシャットダウンして,Ubuntuを起動。カーネルが新しくなっているのを確認。
(管理者コマンドプロンプトで)
wsl –shutdown
(Ubuntuで)
root@e130:~# uname -a
Linux e130 5.10.74.3-microsoft-standard-WSL2+ #3 SMP Thu Nov 18 10:18:05 JST 2021 x86_64 x86_64 x86_64 GNU/Linux
デバイスドライバーのUSB Mass Storage Supportを追加しないと,ブロックデバイスとしてアクセスできなかった(元のカーネルでもUSBデバイスとしては認識されていた)。
USBメモリーをWSL2のUbuntuからアクセスさせたかったので,カーネルのリビルドを行った。
Windows 11で,WSLは,マイクロソフト・ストアからインストールしている。
コメント 0