Skip to content

Instantly share code, notes, and snippets.

@paulproteus
Last active June 5, 2020 19:52
Show Gist options
  • Save paulproteus/b09560bbc0e2efc5d9d5fa2d4abf8ef8 to your computer and use it in GitHub Desktop.
Save paulproteus/b09560bbc0e2efc5d9d5fa2d4abf8ef8 to your computer and use it in GitHub Desktop.
Faster disk erase
openssl enc -aes-256-ctr -pass pass:"$(dd if=/dev/urandom bs=128 count=1 2>/dev/null | base64)" -nosalt < /dev/zero | pv -pterb -s $(blockdev --getsize64 /dev/sdb) | sudo dd bs=4M of=/dev/sdb
Thanks to https://serverfault.com/questions/6440/is-there-an-alternative-to-dev-urandom/415962
Note per https://tches.iacr.org/index.php/TCHES/article/view/8392 it may not be as secure as one might dream, but I'm OK with this given my use.
This lets me write to the disk at 128MiB/s, which is better than the ~20MiB/s I was getting when doing the naive
cat /dev/urandom | pv | sudo dd of=/dev/sdb
Probably the `dd` was using a tiny buffer, but there's also no need for random data as high quality as urandom in this case.
Faster still:
dd if=/dev/urandom bs=8192 count=1 | tr -d '\000' | dd if=/dev/stdin bs=4095 count=1 of=4095.rand
sudo bash -c 'yes `cat 4095.rand` > /dev/sdb'
This breaks iotop :( but oh well.
Confirm with hexedit that it finished properly, then zero-out the first 1MB.
Note that this breaks iotop :(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment