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.

Bryan Hyland
  • 153
  • 1
  • 6

2 Answers2

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
Bryan Hyland
  • 153
  • 1
  • 6
  • I have debian/wsl2, but got error : mkfs.vfat: unable to open \.\\PHYSICALDRIVE2: No such file or directory – Philippe Nov 04 '20 at 22:12
  • I updated the answer due to a typo. This will work if you do \\.\PHYSICALDRIVE2 instead of \.\\PHYSICALDRIVE2. – Bryan Hyland Dec 04 '20 at 16:38
  • Thank you for your reply ! One question : `dd` command is supposed to wipe out the entire PHYSICALDRIVE5, why `mkfs.vfat` is needed ? – Philippe Dec 04 '20 at 18:46
  • 1
    `Get-Wmiobject` is deprecated. use `et-CimInstance Win32_DiskDrive` – rowman Dec 11 '20 at 05:33
  • 3
    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. – dc46and2 Aug 02 '21 at 14:05
  • 1
    @rowman `get-CimInstance Win32_DiskDrive` the first letter 'g' is missing in your comment. – Benoît Dubreuil Sep 16 '21 at 15:16
  • @BenoîtDubreuil Thanks, unable to edit now though – rowman Sep 18 '21 at 05:42
  • I try to use the `dd` command in WSL2, it just create a new file `PHYSICALDRIVE5` instead of writing to the device. – Chau Chee Yang Jan 14 '22 at 04:15
  • 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 FAT32 – ahmedsabriz Jul 19 '22 at 03:47
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.

Bryan Hyland
  • 153
  • 1
  • 6
  • 1
    creating a file system seems pretty much pointless if you're just going to write over it in the next step – Ordoshsen Mar 22 '21 at 20:55