Fill USB Flash with Zeroes on Linux

When formatting usb flash, it always only creates new partition table at the start sectors and remain all the rest as it was. So, it is possible to read the rest data, analyze and get old data if your flash will be in hacker's hands. If your data must be totally removed from flash, it needs to fill entire drive with zeroes.


Fill USB flash with zeroes with dd if=/dev/zero of=/dev/flash

Simplest way is to use 'dd', but it takes much time and reduces lifetime of usb flash:

dd if=/dev/zero of=/dev/FLASH


Fill USB flash with zeroes using ddrescue

Install on Devuan:

apt-cache search ddrescue
gddrescue - GNU data recovery tool

apt install gddrescue

Check flash blocksize

lsblk -o NAME,PHY-SeC /dev/FLASH
sdd        512
└─sdd1     512

For my it is 512.

Create map:

ddrescue -b 512 --generate-mode /dev/zero /dev/FLASH

Fill with zeroes:

ddrescue -b 512 --force --fill-mode=+ /dev/zero /dev/FLASH

For my ancient slow flash "Kingston DataTraveler G3 4Gb" it took 24 minutes. And it removed partitions on it, so need to format flash again after ddrescue.



[1] How to fill a device with zeros, without overwriting the bytes that are already zeros?…