I am trying to use dd to wipe a usb drive using Cygwin on Windows. What should I use for the of argument?
dd if=/dev/null of=?
I am trying to use dd to wipe a usb drive using Cygwin on Windows. What should I use for the of argument?
dd if=/dev/null of=?
It should be noted that writing /dev/null to a block device will do nothing. Block device meaning /dev/sdc not /dev/sdc1 sdc1 refers to the first partition, not the entire device.
You want to use:
/dev/zero
Or:
/dev/urandom
Cygwin uses following device mapping for harddisk-like devices:
POSIX device name Internal NT device name
/dev/sda \device\harddisk0\partition0 (whole disk)
/dev/sda1 \device\harddisk0\partition1 (first partition)
...
/dev/sda15 \device\harddisk0\partition15 (fifteenth partition)
/dev/sdb \device\harddisk1\partition0
/dev/sdb1 \device\harddisk1\partition1
[up to]
/dev/sddx \device\harddisk127\partition0
/dev/sddx1 \device\harddisk127\partition1
...
/dev/sddx15 \device\harddisk127\partition15
You can see NT device names in Disk Management in Management Console.
Also use /dev/zero instead of /dev/null as input.
Assuming Cygwin has the same core commands as a Unix/Linux install, you can us df—which tells you how much free space (disk free) is available on your devices but also gives you nice filesystem data—you can use for situations like this.
For example, here is the output of df from my Mac OS X terminal:
Filesystem 512-blocks Used Available Capacity iused ifree %iused Mounted on
/dev/disk0s2 975093952 135358704 839223248 14% 16983836 104902906 14% /
devfs 381 381 0 100% 660 0 100% /dev
map -hosts 0 0 0 100% 0 0 100% /net
map auto_home 0 0 0 100% 0 0 100% /home
/dev/disk2s2 3906357344 2097411968 1808945376 54% 262176494 226118172 54% /Volumes/Moe
/dev/disk1s2 235154168 118616008 116538160 51% 14826999 14567270 50% /Volumes/Larry
/dev/disk1s3 3670941032 2100018304 1570922728 58% 262502286 196365341 57% /Volumes/Curly
Note the last three entries that show mount points as well as the file system you are connected to. So let’s say I want to erase /Volumes/Curly to replace him at some point with data from a place called /Volumes/Shemp, I would erase all of the data on the drive and then run this dd command:
dd if=/dev/zero of=/dev/disk1s3/wipe_file.txt
And just so you understand what that command does, if indicates what the input file is (get it, if) and of indicates the output file (similarly… get it, of) and that’s that. And I am using /dev/zero instead of /dev/null since /dev/null is an input destination for data you don’t need while /dev/zero is an output source for a stream of 0 characters.
So when you run that dd command the contents of /dev/zero (which is just an endless stream of 0 characters) will be copied to wipe_file.txt on /dev/disk1s3/. Meaning a new file named wipe_file.txt will be created that grows & grows until it fills the full capacity of /dev/disk1s3/.
But depending on how paranoid you are about data, you can also change if to be random like this:
dd if=/dev/random of=/dev/disk1s3/wipe_file.txt
Using zero will explicitly just fill wipe_file.txt with 0 characters while random will fill the file with random characters. Note that filling a file with random data will require more computing power than just filling the file with nothing, so the random method will take longer. But if you are worried about prying eyes recovering data that might be the best thing to assuredly destroy already erased data on a drive.
The most reliable source for drive-letter-mapping for me is a combination of diskpart, blkid and /proc/partitions
user@system:~$ diskpart
Microsoft DiskPart-Version 10.0.19041.964
Copyright (C) Microsoft Corporation.
Auf Computer: SYSTEM
DISKPART> list disk
Datenträger ### Status Größe Frei Dyn GPT
--------------- ------------- ------- ------- --- ---
Datenträger 0 Online 1863 GB 1024 KB *
Datenträger 1 Online 9 TB 1024 KB *
Datenträger 2 Kein Medium 0 B 0 B
Datenträger 3 Kein Medium 0 B 0 B
Datenträger 4 Kein Medium 0 B 0 B
Datenträger 5 Kein Medium 0 B 0 B
Datenträger 6 Kein Medium 0 B 0 B
Datenträger 7 Online 1863 GB 1863 GB
DISKPART> select disk 1
Datenträger 1 ist jetzt der gewählte Datenträger.
DISKPART> list part
Partition ### Typ Größe Offset
------------- ---------------- ------- -------
Partition 1 Reserviert 15 MB 17 KB
Partition 2 Primär 9 TB 16 MB
DISKPART>
user@system:~$ cat /proc/partitions
major minor #blocks name win-mounts
8 0 1953514584 sda
8 1 113664 sda1
8 2 16384 sda2
8 3 1952839766 sda3 C:\
8 4 541696 sda4
8 16 9766436864 sdb
8 17 16367 sdb1
8 18 9766418432 sdb2 D:\
8 32 0 sdc
8 48 0 sdd
8 64 0 sde
8 80 0 sdf
8 96 0 sdg
8 112 1953514584 sdh
8 128 8388608 sdi
8 129 8385536 sdi1
user@system:~$ /sbin/blkid.exe
/dev/sda1: LABEL="SYSTEM" UUID="2A05-C09D" TYPE="vfat"
/dev/sda3: LABEL="Windows" UUID="087A36A47A368E86" TYPE="ntfs"
/dev/sda4: UUID="A080B84E80B82CA2" TYPE="ntfs"
/dev/sdb2: LABEL="Data" UUID="1864245164243442" TYPE="ntfs"
/dev/sdi1: LABEL="PortableBaseLayer" UUID="6278D53678D50A25" TYPE="ntfs"
While I would definitely prefer a device list with real drive names (Seagate ST2000DM001 or something like that) I can easily work out the drive mapping by checking the output of the previous commands. And make sure to double and tripple check, nothing is more hilarious than whipping your C:-Drive.