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.

3
  • 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. Commented Jun 13, 2023 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
    Commented Jun 13, 2023 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. en.wikipedia.org/wiki/…. Commented Jun 14, 2023 at 14:56

4 Answers 4

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.

3
  • 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. Commented Jun 12, 2023 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
    Commented Jun 13, 2023 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. Commented Jun 13, 2023 at 15:58
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

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

3
  • 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!). Commented Jun 15, 2023 at 20:45
  • I was referring to usb sticks, not spinning disks, to (not) do this to. Commented Jun 15, 2023 at 20:51
  • Ah, now your comment makes way more sense! Let me clean up mine! Commented Jun 15, 2023 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.

1
  • This assumes the partition structure is ok, you need to create the partitions before you can run mkfs Commented Jun 16, 2023 at 8:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .