5

I have a hard drive that I want to overwrite, not with null bytes, but with a message.

48 69 64 64 65 6e 20 = "Hidden "

Here's my command thus far:

echo "Hidden " > /myfile
dd if=/myfile of=/dev/sdb bs=1M

Note: I have also tried an assorment of parameters such as count and conv to no avail

Now, this is fine. When I run:

dd if=/dev/sdb | hexdump -C | less

I can see the first few bytes written over, however, the rest is unchanged. I'd like to recursively write "Hidden " to the drive.

jscs
  • 63,694
  • 13
  • 151
  • 195
Goodies
  • 4,439
  • 3
  • 31
  • 57
  • 4
    You meant `repeatedly`, not `recursively`. See [recursion on Wikipedia](https://en.wikipedia.org/wiki/Recursion_%28computer_science%29) – 1ace Dec 21 '13 at 01:15
  • 1
    Your question has been already answered and accepted, but here's a helpful hint for saving you some typing: `dd if=/dev/sdb | hexdump -C | less` Can be written as: `hexdump -C /dev/sdb | less` – OmnipotentEntity Dec 21 '13 at 01:55

3 Answers3

14

I don't have a spare disk to try this out on, but you can use the yes command to continuously push your string into the pipe:

yes "Hidden" | dd of=/dev/sdb

I assume once dd has written the whole disk, then it will close the pipe and this command will finish.

The above will newline-delimit the "Hidden" string. If you want it space-delimited, as in the question you can do:

yes "Hidden" | paste -d' ' -s - | dd of=/dev/sdb

Or if you want it null-delimited:

yes "Hidden" | tr '\n' '\0' | dd of=/dev/sdb
Digital Trauma
  • 15,475
  • 3
  • 51
  • 83
  • This one did it! Thanks! The paste command isn't required, but it's a lot neater in there with a null delimiter. – Goodies Dec 21 '13 at 01:34
  • +1 from me too, learn something every day, never heard of the `yes` command :) – Niels Keurentjes Dec 21 '13 at 01:39
  • 1
    Yes, the `paste` command isn't strictly necessary unless you want "Hidden" to be space-delimited. Otherwise it will be newline-delimited. Glad it worked for you! – Digital Trauma Dec 21 '13 at 01:41
3

If you don't specify if parameter, input is read from stdin. This allows you to do something like this:

dd of=/dev/sdb < for((i=0;i<100000;i++)); do echo 'Hidden '; done;

The value of 100000 obviously needs to be at least diskSizeInBytes / strlen('Hidden ').

Given the consequences I didn't test this for you but it ought to work ;)

Niels Keurentjes
  • 41,402
  • 9
  • 98
  • 136
  • Hmmm... it didn't seem to take the parenthesis, so building off of your idea I made this: `for((i=0;i<100000;i++)); do echo 'Hidden ' | dd of=/dev/sdb; done;` which seems to simply write "Hidden " 100000 times in the first bytes :) – Goodies Dec 21 '13 at 01:20
  • You're doing it the wrong way round - you're now starting `dd` 100000 times instead of piping the combined output of 100000 echos to it once. Move the entire `dd` call out of the loop. – Niels Keurentjes Dec 21 '13 at 01:22
2

dcfldd, a fork of dd, has some additional features that you may find useful. For example, your problem would be solved by:

dcfldd textpattern="Hidden " of=/dev/sdb bs=1M
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173