I found bad sectors on my usb external drive and so I want to perform a full wipe overwriting the disk with zeroes. I found this command:

sudo dd if=/dev/zero of=/dev/sd<disk-letter> bs=8M

and I have some questions:

  • Is the block size value correct or should I set a different value depending if the disk is internal or external?
  • Is there another command in case of a pen drive or a SSD drive?
  • After I've deleted all partitions and created a new partition table by Gparted, should I also create a new partition (e.g. ext4) before typing the above command?

Thank you! :)

  • 1
    A word of caution: you want to check that you're overwriting the correct disk very, very carefully – grooveplex Oct 10 '16 at 17:39
  • The block size does not really matter when using dd, it only affects the speed of the operation. Basically you should use 4M or a multiple of that as block size. Smaller blocks make the process slower, but larger block sizes usually don't really speed it up much more.

  • Flash drives can't get bad blocks the way HDDs with spinning magnetic platters do. They consist of memory cells that wear out with every erase/overwrite.

    Therefore such devices have a controller chip built in that works as wear leveller which tries to equally distribute the writes over all cells to make them last as long as possible. Normally good flash drives and SSDs also contain much more cells than declared as their capacity, so that even after some cells died, the device is still working because the controller still has enough working cells to assign.

    If a flash drive/SSD starts to cause I/O errors, it's really at the edge of dying. There's nothing you can fix with overwriting everything with zeroes, the additional erase/write cycle just wears the cells out more. And due to the controller, you can't even be sure that (or rather, you can sure that not) all cells get overwritten once. It may also overwrite the same cell multiple times and others not, and it may use some of the spare cells it has.

    In short, don't zero out flash drives or SSDs. It does not help with anything (not even for secure data erasure) and only wears the drive out more. If such a drive starts throwing I/O errors, replace it.

  • dd if=/dev/zero of=/dev/sdX bs=4M (with /dev/sdX being a device like /dev/sdb, not a partition like /dev/sdb1) operates directly on the raw disk, not respecting any partitioning. Zeroing a drive out with this command effectively wipes out the boot sector, partition table and all partitions equally. That said, it does not matter what you do before zeroing out the drive. You can partition it, format it, fill it with random data or whatever you like - in the end it will all be nuked. So just leave it and zero it out directly.

  • Thanks a lot for your detailed answer. Very clear! :) Anyway, is there a similar command to perform a more advanced wipe, for example three (1-0-1) or more overwriting passes? – Generoso Oct 10 '16 at 21:39
  • You might want to try out shred (see man shred for more info), but that uses random patterns. However, I'm not sure if that would help you in your situation. – Byte Commander Oct 10 '16 at 21:45
  • Why a multiple of 4M? – Hashim Aziz Apr 11 '18 at 22:21
  • @Hashim See e.g. superuser.com/q/234199/418736 or stackoverflow.com/q/6161823/4464570. bs specifies the block size, i.e. the amount of bytes copied at once. The optimal size heavily depends on the underlying hardware and/or file system, but 4M should be a reasonable modern default. Lowering the block size tends to quickly decrease performance significantly, while raising it usually only yields smaller improvements. And using powers of 2 is a good idea most times, but the effect is probably not that big. – Byte Commander Apr 11 '18 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.