Score:11

Linux / BSD "quickly" wipe a USB drive?

us flag

I'm clearing a drive with dd. It's a USB device and 120GB and it's taking a very long time:

dd if=/dev/zero of=/dev/da0 bs=1M status=progress

I have tried messing with the block size (smaller and larger values bs=4M, bs=8M, etc) but nothing seems to make much of a difference. It's writing at about 7000 kB/s which is painfully slow.

I do not care about "securely" wiping the data I just want it wiped so I can re-establish the partition structure and filesystem from scratch. Is there an alternate way (using standard utilities) that can perform a quick (within a minute or two) wipe for this type of scenario? The device I'm working on is FreeBSD but I think the dd command (and gpart, etc) work similarly between it and Linux.

mx flag
Actually, the FreeBSD `dd` has significant differences from the GNU `dd` used on most Linux systems. None of those differences are likely to matter for your use case though.
HBruijn avatar
in flag
*"I do not care about "securely" wiping the data I just want it wiped so I can re-establish the partition structure and filesystem from scratch."* - Then don't wipe at all, simply skip the wiping and immediately run your favourite partitioning tool and format the new partition(s) with your favourite file system(s).
Paul Johnson avatar
in flag
The reason this is so slow is that as far as the drive knows it's got to store all those zeros you are writing to it, and also the data that you haven't got to yet. So its shuffling this data around in case you should stop writing zeros and start reading sectors. Cheap thumb drives in particular are very bad at this. https://en.wikipedia.org/wiki/Write_amplification#:~:text=Write%20amplification%20(WA)%20is%20an,amount%20intended%20to%20be%20written.
Score:19
cn flag

The Linux command to remove all disklabel and file systems signatures is:

wipefs -a /dev/sd###

Most modern flash disks and flash USB sticks are supporting TRIM / DISCARD / SCSI UNMAP. For USB you need to enable it:

# cat /sys/block/sd###/device/scsi_disk/*/provisioning_mode
full
# echo unmap > /sys/block/sd###/device/scsi_disk/*/provisioning_mode
# cat /sys/block/sd###/device/scsi_disk/*/provisioning_mode
unmap
#

If trim is enabled you can destroy all data with:

blkdiscard /dev/sd###

Replace sd### with something like sdx or nvme9n9. You can list all block devices with: lsblk

Score:15
in flag

The fastest way is to remove all partitions on the drive. This will "remove" also filesystems. And zero first megabyte (boot record and so).

dd if=/dev/zero of=/dev/da0 bs=1M count=1

and you have "brand new" disk.

Marcus Müller avatar
pt flag
well, let me nitpick there: it'll not *remove* the filesystems, it will make them impossible to find by the operating systems. They could quite likely be recovered. But 100% agree, if "securely" wiping isn't necessary, that's sufficient.
kz flag
Bob
This would not work for GPT, as there is a backup copy of the partition table stored at the end of the disk.
Mark Morgan Lloyd avatar
us flag
Leaving aside the GPT issue: my recollection is that one of the differences between fdisk on MS/PC-DOS and fdisk on Linux is that the DOS variant also blanks out the first sector or so of any removed filesystem. Subject, I'd note, to anything the OEM (PC Supplier) has done since originally at least it was their responsibility to build fdisk.
Score:10
pt flag

There's different kinds of USB storage devices.

If your device supports it,

blkdiscard /dev/da0

on Linux, or

trim /dev/da0

on FreeBSD

will tell the drive to just drop all data. That's going to be very quick, as it basically is just telling the wear leveling table that "hey, forget that any of the blocks ever were used for data, and treat them as ready to be nulled and used again".

Even if it's that quick, it will have the nice side effect of "nulling", i.e. it makes the old data irrecoverable (short of opening the hardware, circumventing the storage controller inside, and reading raw data an taking a huge guess on what block in which order needs to be reassembled).

cn flag
This might be the only "great" way, if it can be made to work on usb drives. Advice to null the whole device through like you would with an old school hard disk might a) leave more data intact than you want and b) wear the drive out a lot or even damage it if done repeatedly (I had bottom-drawer usb sticks fail after nulling them a few times!).
cn flag
I was referring to usb sticks, not spinning disks, to (not) do this to.
Marcus Müller avatar
pt flag
Ah, now your comment makes way more sense! Let me clean up mine!
Score:7
ws flag

I do not care about "securely" wiping the data I just want it wiped so I can re-establish the partition structure and filesystem from scratch

Just run mkfs on the partitions.

bd flag
This assumes the partition structure is ok, you need to create the partitions before you can run mkfs
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.