11

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.

200_success
  • 4,771
  • 1
  • 25
  • 42
Rino Bino
  • 511
  • 5
  • 21
  • 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. – Austin Hemmelgarn Jun 13 '23 at 11:11
  • 24
    *"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). – HBruijn Jun 13 '23 at 13:10
  • 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. – Paul Johnson Jun 14 '23 at 14:56

4 Answers4

19

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

Mircea Vutcovici
  • 17,619
  • 4
  • 56
  • 83
15

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.

Romeo Ninov
  • 5,263
  • 4
  • 20
  • 26
  • 11
    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. – Marcus Müller Jun 12 '23 at 20:42
  • 3
    This would not work for GPT, as there is a backup copy of the partition table stored at the end of the disk. – Bob Jun 13 '23 at 11:39
  • 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. – Mark Morgan Lloyd Jun 13 '23 at 15:58
10

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).

Marcus Müller
  • 500
  • 4
  • 13
  • 1
    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!). – rackandboneman Jun 15 '23 at 20:45
  • I was referring to usb sticks, not spinning disks, to (not) do this to. – rackandboneman Jun 15 '23 at 20:51
  • Ah, now your comment makes way more sense! Let me clean up mine! – Marcus Müller Jun 15 '23 at 20:54
7

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.

symcbean
  • 21,009
  • 1
  • 31
  • 52