Skip to content

Instantly share code, notes, and snippets.

@rmi1974
Last active October 24, 2023 12:46
Show Gist options
  • Save rmi1974/08e22df0372fe20cfae1f2f26a88370c to your computer and use it in GitHub Desktop.
Save rmi1974/08e22df0372fe20cfae1f2f26a88370c to your computer and use it in GitHub Desktop.
How to wipe the entire disk in Linux #diskwipe #security #commandlinefu

Wiping the entire disk in Linux

Using 'dd'

This will overwrite all partitions, master boot records, and data. Filling the disk with all zeros.

WARNING: might take a long time depending on disk size

sudo dd if=/dev/zero of=<disk/partition> bs=1M

If you are wiping your hard drive for security, you should populate it with random data rather than zeros.

WARNING: might take a long time depending on disk size

sudo dd if=/dev/urandom of=<disk/partition> bs=1M

To provide a nifty progress bar:

pv -ptres "Size of disk in gigabytes followed by a G" /dev/urandom | sudo dd of=/dev/sda bs=1M

Using 'shred'

Shred the given file/partition/disk by overwriting it first with random data and then with 0x00 (zeros).

WARNING: might take a long time depending on disk size

$ sudo shred -vfz -n 1 /dev/sdb
shred: /dev/sdb: pass 1/2 (random)...
shred: /dev/sdb: pass 1/2 (random)...514MiB/1.9TiB 0%
shred: /dev/sdb: pass 1/2 (random)...1.0GiB/1.9TiB 0%
shred: /dev/sdb: pass 1/2 (random)...1.6GiB/1.9TiB 0%
shred: /dev/sdb: pass 1/2 (random)...2.2GiB/1.9TiB 0%
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment