Write random bytes to disk using shred

Sometimes you need to wipe out the entire disk with random bytes. This could be due to metadata used by your filesystem such as zfs where formatting or wiping the parition table and disk may not be enough. We can use shred to securely delete a file or disk.

  • First get the disk name using lsblk or fdisk -l.
  • Then use shred to write random bytes to the disk.
shred -v -n 1 --random-source=/dev/urandom /dev/sdX
  • -v enables verbose mode displyaing the progress.
  • -n 1 specifies the number of passes to write random bytes.
  • --random-source=/dev/urandom specifies the source of random bytes.
  • /dev/sdX is the disk name.

To securely delete a file use filename instead of the disk name.

shred -v -n 10 --random-source=/dev/urandom filename.txt