-2

I am preparing a device with shred to use it later on encrypted with dm-crypt/cryptsetup/luks.

How can I check the device before and after using shred or e.g openssl/dd with /dev/urandom to be sure what was done? Is there a possibility?

MadHatter
  • 79,770
  • 20
  • 184
  • 232
John Jane
  • 1
  • 4

1 Answers1

3

On a POSIX system, a disk device is a file so it can be read from by any tool which supports reading from files—be it cat, dd or even LibreOffice Writer (OK, just kidding).

So basically you have two issues to sort out:

  • How to interpret what will be read.
  • Decide if whatever you'll observe means your test has been passed or failed.

Since your disk drive will contain generally non-human-readable data, the simplest way to view it by eye is to use something like od (should be available right away) or xxd (a bit more convenient but might not be available on a minimal system). So, somehting like

# od </dev/sda3 | less

should be OK to see what's there on the disk drive.

The second issue is trickier as it's more philosophic than technical (what @sebix tried to point out). The problem is that it's unclear what do you really mean. If you want to somehow measure randomness of the data after your openssl and /dev/urandom encantation, you have to 1) come up with a way to define a method to measure that randomness; 2) execute it.

I doubt you have really meant something like that though and will make a wild guess: you probably just wanted to see if the data on the disk drive does merely look random.

If yes, then the simplest way would be to first dd if=/dev/zero of=/dev/sda3 ... to fill the drive with zero bytes, then re-write it using your "random encantation" and then use od or a similar tool to verify there's really random data on the drive.

If, instead, you did really mean to measure the randomness of your data, then it's just an improper place to ask: try asking on the math.stackexchange.com and tag your question as being related to statistics. In other words, a way to read the data is a technical question, a way to perform a statistical analysis on it is not.

kostix
  • 1,150
  • 1
  • 7
  • 13
  • You can do the first. You cannot do the second; it is impossible. There is no *post facto* test that can confirm that data were generated by a truly random process. – MadHatter Feb 27 '15 at 18:44
  • Because it is a new device I assumed it is "empty" aka filled with zeros (I performed the ATA erase cmd) and wanted to just see if the data on the disk does merely look random. TY so much for applying Hanlon's Razor to my question. – John Jane Feb 27 '15 at 19:59
  • @MadHatter, I was thinking more about analysis of the data available. Say, if the drive has alterating blocks of all zeroes and all-`0xff`, the data is not random, and if the analysis fails to see *a pattern* in that data, it's random. Yes, I'm not much into statistical distribution and stochastic processes ;-) – kostix Feb 27 '15 at 23:05