How can I use the linux dd command on wsl2 to burn a bootable usb?
Asked Answered
J

2

7

I am an avid Linux user who is being made to use Windows for work. I was given the go-ahead to install WSL2 and Ubuntu on the work computer. I would like to burn a bootable USB using dd in WSL2, but haven't been able to figure out how to get the device since lsblk doesn't supply the external block devices connected to the computer. I understand I could do it in something like Rufus, but since it's a work computer I'm not allowed to get anything like that on the computer.

There is only one other question like this on StackOverflow, but it is closed and did not give an answer. However it did give a clue for me to start looking for the physical device name. Using that clue, I have figured out the answer to this question and wanted to share it since there are no answers I could find not only on StackOverflow, but anywhere else on the internet.

Jael answered 4/11, 2020 at 16:21 Comment(0)
J
3

PowerShell:

# 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"}

Ubuntu 20.04 Terminal:

# 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
Jael answered 4/11, 2020 at 16:21 Comment(9)
I have debian/wsl2, but got error : mkfs.vfat: unable to open \.\\PHYSICALDRIVE2: No such file or directoryMukluk
I updated the answer due to a typo. This will work if you do \\.\PHYSICALDRIVE2 instead of \.\\PHYSICALDRIVE2.Jael
Thank you for your reply ! One question : dd command is supposed to wipe out the entire PHYSICALDRIVE5, why mkfs.vfat is needed ?Mukluk
Get-Wmiobject is deprecated. use et-CimInstance Win32_DiskDriveSnowstorm
I don't think Linux in WSL treats paths like \\.\PHYSICALDRIVE5 specially. This is probably just creating a normal file named \.PHYSICALDRIVE5 (after the shell removes some backslashes) in the current directory. I.e. I doubt this is actually updating your thumbdrive.Gad
@Snowstorm get-CimInstance Win32_DiskDrive the first letter 'g' is missing in your comment.Agonistic
@BenoîtDubreuil Thanks, unable to edit now thoughSnowstorm
I try to use the dd command in WSL2, it just create a new file PHYSICALDRIVE5 instead of writing to the device.Evansville
I get "unable to open \\.\PHYSICALDRIVE1: No such file or directory" on WSL2 Ubuntu 20.04. I can mount the usb but I cannot detect it using mkfs.vfat, fdisk or parted. It's FAT32Venetic
J
0

The answer to the question of mkfs.vfat is that I have a habit of ensuring that the usb I’m using is formatted to FAT32. I guess it’s not required, but definitely a step I always take.

Thank you, @rowman, I didn’t know it was deprecated. I will use Get-CimInstance Win32_DiskDrive from now on. Much easier than formatting Get-WmiObject with a Where-Object call.

Jael answered 12/12, 2020 at 18:47 Comment(1)
creating a file system seems pretty much pointless if you're just going to write over it in the next stepAttract

© 2022 - 2024 — McMap. All rights reserved.