How to use dd on WSL?

20,324

Solution 1

This is a category error in usage. dd doesn't work with directories, it works with files. The files can be device files (like /dev/sda or /dev/urandom on Linux), or regular files (like echo foo >> myfile.txt). What you're trying to pass is a directory in a mounted filesystem.

Unfortunately, WSL doesn't seem to support accessing your block device files (i.e. it doesn't have /dev). You can follow this feature request on their issue tracker to see when they will add support.

Solution 2

As @asad-saeeduddin has said, WSL doesn't have block level access, but that doesn't mean that you can't use dd on Windows!

I've found out that dd is part of the set of tools that are installed along with Git for Windows. After install you can find it in C:\Program Files\Git\usr\bin\dd.exe

The Windows equivalent to /dev/sda is \.\PHYSICALDRIVE0 and you can find the proper IDs for your local machine's devices with this command (also returns the sector sizes):

Get-WmiObject Win32_diskdrive | select Caption,DeviceID,BytesPerSector,InterfaceType,Size
Share:
20,324
Jet Blue
Author by

Jet Blue

Updated on October 30, 2020

Comments

  • Jet Blue
    Jet Blue over 3 years

    How can I used the dd command to dump the contents of a removable disk in WSL?

    When I run,

    dd if=/mnt/d of=sdDump bs=512 count=1
    

    I get the error dd: error reading '/mnt/d': Is a directory

    I followed the steps shown here to mount the disk:

    sudo mkdir /mnt/d
    sudo mount -t drvfs D: /mnt/d
    

    Doing this allows me to see the files on the disk via ls, but running dd yields the above error.

  • Asad Saeeduddin
    Asad Saeeduddin about 6 years
    Unfortunately, i don't think dd if=D: will work; WSL doesn't have support for accessing the block device files.
  • santiago arizti
    santiago arizti almost 5 years
    any updates on this? maybe with WSL2 being available on Insider program with real linux kernel?