如何在 wsl2 上使用 linux dd 命令刻录可启动 USB?

Bry*_*and 7 powershell dd windows-subsystem-for-linux wsl-2

我是一名狂热的 Linux 用户,但在工作中被迫使用 Windows。我被允许在工作计算机上安装 WSL2 和 Ubuntu。我想在 WSL2 中使用 dd 刻录可启动 USB,但无法弄清楚如何获取该设备,因为 lsblk 不提供连接到计算机的外部块设备。我知道我可以在 Rufus 之类的东西上做到这一点,但由于它是一台工作计算机,所以我不允许在计算机上获取类似的东西。

StackOverflow上只有一个这样的问题,但它已关闭并且没有给出答案。然而,它确实为我开始寻找物理设备名称提供了线索。利用这条线索,我找到了这个问题的答案,并想分享它,因为我不仅在 StackOverflow 上找不到答案,而且在互联网上的其他任何地方都找不到答案。

Bry*_*and 3

电源外壳:

# I ran this command to get the DeviceID of my USB Thumbdrive (Mine came out to be
# \.\\PHYSICALDRIVE 5, but yours may vary)
Get-WmiObject Win32_diskdrive | Select Caption,DeviceID,InterfaceType,Size | Where-Object {$_.InterfaceType -eq "USB"}
Run Code Online (Sandbox Code Playgroud)

Ubuntu 20.04 终端:

# After I got the physical drive number from powershell (as I would do using lsblk in Linux) I
# formatted the drive using mkfs to ensure it would work before trying to use dd.
sudo mkfs.vfat -I \\.\PHYSICALDRIVE5

# After a successful format, I was able to run dd as normal
sudo dd if=path/to/my/file.iso of=\\.\PHYSICALDRIVE5 status=progress
Run Code Online (Sandbox Code Playgroud)

  • 我不认为 WSL 中的 Linux 会特别对待 \\.\PHYSICALDRIVE5 这样的路径。这可能只是在当前目录中创建一个名为 \.PHYSICALDRIVE5 的普通文件(在 shell 删除一些反斜杠之后)。也就是说,我怀疑这实际上是在更新您的拇指驱动器。 (3认同)