0

I have a disk which is perhaps broken. I want to write random data to the disk and later verify the md5 checksum.

I write to the disk like this:

dd if=/dev/urandom of=/dev/sda bs=4M status=progress

How to create the md5 checksum while writing to the disk at the same time? I want to see the md5 checksum of the written random data when dd finishes. Also I want to see the progress while writing to the disk.

I have read this post and I created this command:

pv /dev/urandom >(md5sum) > /dev/sdXXX

The problem is it fills up my whole RAM. I got 32GB RAM.

zomega
  • 821
  • 7
  • 19
  • Does this answer your question? [Is there a way to pipe the output of one program into two other programs?](https://unix.stackexchange.com/questions/40277/is-there-a-way-to-pipe-the-output-of-one-program-into-two-other-programs) – Artem S. Tashkinov Dec 24 '22 at 18:21
  • It's possible (for example using tee). If you're open to alternatives, you can also use cryptsetup instead, example https://unix.stackexchange.com/a/681556/30851 – frostschutz Dec 24 '22 at 19:58
  • @ArtemS.Tashkinov I have read it and I got a command now. But the problem is it fills up my whole RAM and I got 32GB. So I clicked "no" when I was asked if this post solves my problem. The command I got is: pv /dev/urandom >(md5sum) > /dev/sdXXX – zomega Dec 24 '22 at 20:10
  • Instead of writing random data could you use `badblocks -w -s` instead? It does a write to each block followed by a read and a compare and will show progress of the scan. – doneal24 Dec 24 '22 at 20:48
  • @doneal24 I think this is exactly what I was looking for. – zomega Dec 24 '22 at 21:00
  • I wrote this up as an answer to the problem even if it doesn't answer the question asked. Consider accepting the answer if it meets your needs. – doneal24 Dec 24 '22 at 21:08

1 Answers1

1

Rather than write your own solution you can use a standard scan utility.

badblocks -w -s /dev/sda

will scan the entire disk, writing patterns to each individual block then reading the block back and comparing the results. Progress is displayed during the scan. You can also specify a number of passes if the default single pass doesn't seem like enough.

doneal24
  • 4,910
  • 2
  • 16
  • 33