How to Physically Mount a USB Flash Drive in WSL2 and Write an ISO Image
When writing ISO images to removable media such as USB flash drives on a Windows OS, dedicated GUI tools are typically used. However, in cases involving devices with special partition structures or operations restricted by the OS-standard disk management tool, Linux-standard command-line tools provide more reliable and flexible operations.
This article explains how to bypass Windows-side restrictions and directly control a USB flash drive as a physical device within the Windows Subsystem for Linux 2 (WSL2) environment.
Bridging WSL2 and Physical Devices
By default, WSL2 limits access through the Windows-side file system and cannot directly recognize physical devices connected to the USB bus. The objective of this task is to use a third-party tool to pass through the USB device to WSL2, making it directly operable from the Linux kernel as /dev/sdX.
As our target, we aim to write the ISO image accurately in block units using the dd command, completing the write process while maintaining data integrity.
Attachment Restrictions Due to Removable Attributes
WSL2 includes a command called wsl --mount, but this is primarily intended for VHDs (virtual disks) and fixed disks. Running this against “removable media" like a USB flash drive causes an error such as “The specified file was not found" or “The operation is not supported" due to Windows-side exclusive control, making it impossible to attach. This OS-layer restriction acts as a barrier to native Linux disk operations.
Installing usbipd-win and Executing Passthrough
To solve this issue, we will introduce usbipd-win, which utilizes the USB/IP protocol to transfer devices.
Tool Installation and Initial Setup
In an administrator PowerShell on Windows, run the following command to install the tool. After installation, restarting PowerShell is required to apply the settings.
PS C:\\> winget.exe install usbipd 既存のパッケージが既にインストールされています。インストールされているパッケージ...をアップグレードしようとしています 見つかりました usbipd-win [dorssel.usbipd-win] バージョン 5.3.0 このアプリケーションは所有者からライセンス供与されます。 Microsoft はサードパーティのパッケージに対して責任を負わず、ライセンスも付与しません。 ダウンロード中 https://github.com/dorssel/usbipd-win/releases/download/v5.3.0/usbipd-win_5.3.0_x64.msi ██████████████████████████████ 4.29 MB / 4.29 MB インストーラーハッシュが正常に検証されました パッケージのインストールを開始しています... インストールが完了しました
Identifying and Binding the Device
With the USB flash drive connected, display the list of devices using the following command.
PS C:\\> usbipd.exe list Connected: BUSID VID:PID DEVICE STATE 1-8 8087:0032 インテル(R) ワイヤレス Bluetooth(R) Not shared 4-1 046d:c548 Logitech USB Input Device, USB 入力デバイス Not shared 4-3 0781:5580 USB 大容量記憶装置 Not shared Persisted: GUID DEVICE xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx USB 大容量記憶装置 xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx USB 大容量記憶装置
Check the BUSID (e.g., 4-3) displayed on the left side of the target USB flash drive (e.g., SanDisk USB Device). Next, perform a “bind" operation to make that device shareable.
usbipd.exe bind --busid 4-3
Attaching to WSL2
With your WSL2 (Ubuntu, etc.) instance running, execute the following command to connect the device to the Linux side.
PS C:\\> usbipd.exe attach --busid 4-3 --wsl usbipd: info: Using WSL distribution 'Ubuntu-22.04' to attach; the device will be available in all WSL 2 distributions. usbipd: info: Loading vhci_hcd module. usbipd: info: Detected networking mode 'nat'. usbipd: info: Using IP address 172.xx.xx.x to reach the host.
This disconnects the device from the Windows side and recognizes it as a physical device on the WSL2 side.
Writing on the Linux Side and Safe Removal
Switch to the WSL2 terminal and follow the steps below to write the ISO image.
Confirming the Device Name
Run the lsblk command to check the name of the newly recognized disk. Judging by the size, it should be displayed as something like /dev/sde.
Writing via the dd Command
Write the ISO image using the dd command to the confirmed device name (e.g., /dev/sde).
# if=input file, of=output device, bs=block size, status=progress display sudo dd if=harvester-v1.7.1-amd64.iso of=/dev/sdf bs=4M status=progress conv=fdatasync 7788822528 bytes (7.8 GB, 7.3 GiB) copied, 216 s, 36.0 MB/s 1859+1 records in 1859+1 records out 7798194176 bytes (7.8 GB, 7.3 GiB) copied, 343.974 s, 22.7 MB/s
After writing is complete, be sure to run the sync command to completely flush the memory cache to the physical disk.
sync
Software Detachment
Once the write operation is finished, return to Windows PowerShell and detach the device from WSL2 using the following command.
PS C:\\> usbipd.exe detach --busid 4-3
This operation returns the device to a safely removable state.
Conclusion and Practical Insights
By combining WSL2 and usbipd-win, you can apply powerful Linux disk manipulation tools to USB media without being bound by the logical constraints of the Windows OS. Being able to create reliable images using the standard dd command without introducing dedicated writing software is an extremely effective method for server building and system maintenance.
This technique can certainly be called one of the most reliable choices for OS installation work on specific hardware, such as turning a Surface Pro 5 into a server.