13

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.

Jet Blue
  • 5,109
  • 7
  • 36
  • 48
  • For the "if" argument, use the device you passed to the mount command, not the name of the directory you mounted it to. – pcjr May 23 '18 at 15:02
  • @pcjr Hi, could you elaborate? What do you mean by "use the device"? – Jet Blue May 25 '18 at 16:07
  • Use block devices. Since WSL does not support them, I recommend [cygwin](https://cygwin.org/) or [cmder](https://cmder.net/). Please note you'll need to open a terminal as administrator, then run `dd if=/dev/sdb of=sdDump bs=512 count=1 status=progress`. – simlev Sep 18 '19 at 08:22

3 Answers3

22

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.

Asad Saeeduddin
  • 46,193
  • 6
  • 90
  • 139
8

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
Chirishman
  • 327
  • 4
  • 6
-1

The typical usage of the mount command is to specify what you want to mount (a device, on *nix a device is really just a special type of file) and where you want to mount it (a directory). The dd command wants some type of file. In your example, D: is the device, so this is the argument you need to pass to dd:

dd if=D: of=sdDump bs=512 count=1

Disclaimer: I do not have WSL experience, but I have been using mount and and dd for decades.

pcjr
  • 419
  • 2
  • 6