Matt Borja

Zero a USB Flash Drive

To zero out a USB flash drive, first verify the device you are about to wipe.

$ sudo fdisk -l
...
Disk /dev/sda: 29.8 GiB, 32015679488 bytes, 62530624 sectors
Disk model: USB Flash Drive 
...

Device     Boot Start      End  Sectors  Size Id Type
/dev/sda1        2048 62527487 62525440 29.8G  7 HPFS/NTFS/exFAT

In this case, my USB flash drive is located at /dev/sda1 and is 32015679488 bytes (or 32 GB).

As we know, you can zero out this drive is to use the dd command.

$ sudo umount /dev/sda1
$ sudo dd if=/dev/zero of=/dev/sda1

This will of course take some time. However, I always like to independently verify that these things actually work as intended, thus you can also monitor its progress by sampling a hex dump of the device while the command is running.

$ sudo hexdump -v /dev/sda1 | less
0000000 0000 0000 0000 0000 0000 0000 0000 0000
0000010 0000 0000 0000 0000 0000 0000 0000 0000
0000020 0000 0000 0000 0000 0000 0000 0000 0000
0000030 0000 0000 0000 0000 0000 0000 0000 0000
0000040 0000 0000 0000 0000 0000 0000 0000 0000
0000050 0000 0000 0000 0000 0000 0000 0000 0000
0000060 0000 0000 0000 0000 0000 0000 0000 0000
0000070 0000 0000 0000 0000 0000 0000 0000 0000
0000080 0000 0000 0000 0000 0000 0000 0000 0000
...

Note: If you run hexdump without the -v option, you will see all zeroed addresses truncated with an asterisk, after which the next address to appear will effectively be the progress of dd.