Some day you will probably run into the situation where you will want to zero a drive. Whether it be for security, privacy, or destruction of evidence (hopefully not this one) there are many reasons to want to write all zeros to a disk. For me, I had received some used disks from a friend and wanted to check their integrity by writing to every bit of the drive with the added benefit of removing any partition table or RAID superblock that may cause trouble down the line. I am planning on using the disks in a raid1 configuration so if I didn’t zero my drives my raid card would have to build a 1TB raid which would take awhile. Alternatively if I zero the drives, my cpu writes out zeros very quickly and then the raid card easily verifies that the disks match.
Zeroing the Drive
First identify the disk you want to zero.
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT fd0 2:0 1 4K 0 disk sda 8:0 0 74.5G 0 disk ├─sda1 8:1 0 1007K 0 part ├─sda2 8:2 0 20G 0 part / ├─sda3 8:3 0 8G 0 part [SWAP] └─sda4 8:4 0 46.5G 0 part /home sdb 8:16 0 931.5G 0 disk sr0 11:0 1 1024M 0 rom
My 1TB drive showed up under
/dev/sdb though this is likely different in your setup so please be careful. The last thing you want to do is write zeros over your personal data and/or system files. dd doesn’t care if those pictures are irreplaceable, dd doesn’t care that your master’s thesis took months to write, it doesn’t even care if it deletes the operating system that instructed it to run in the first place. It’s basically a honey badger, so use with caution. Obligatory warning:
Warning: There is no confirmation regarding the sanity of the dd command so repeatedly check that the correct drive or partition has been targeted. Make certain that the of=… option points to the target drive and not to a system disk.
Below is the command to zero the drive, replace
/dev/sdx with your drive:
# dd if=/dev/zero of=/dev/sdx iflag=nocache oflag=direct bs=4096
Now if you’re like me, you’re going to want track the progress of the operation. We can do this by opening another terminal and running the following command:
$ sudo watch -n 30 'pkill -USR1 -n -x dd'
You can read more about securely wiping disks here: https://wiki.archlinux.org/index.php/Securely_wipe_disk
That’s it, thanks for reading! If you found this helpful, let me know on twitter or facebook. It’s always good to get feedback so I know to keep writing.