2

We have a relatively large disk on our Linux machine, 2.5TB in size.

We want to completely format (zero-out) this disk; say the disk is /dev/sdX.


We would like to achieve this with dd, for example:

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

My question is: Does dd also support such a formatting (cleaning) of disks with large sizes?

Additionally, what could be the verification method after such dd operation, in order to see if the disk has really been zeroed?

yael
  • 13,106
  • It's unclear if this is about data security or whether it's about simply emptying the disk. Ordinarily, newfs creates a new (empty) filesystem. – Kusalananda Jan 27 '18 at 18:51
  • Format a new disk? Make a partition using fdisk or gparted or whatever you like and then mkfs.ext4 (or whatever fs you want to use) on it – ivanivan Jan 27 '18 at 18:52
  • we just want to clesn the sdb disk as a new disk , dose dd give this ability ? – yael Jan 27 '18 at 18:58
  • 1
    With count=1 you only wipe the partition table, in that case perhaps you want wipefs instead ( https://unix.stackexchange.com/a/394999/30851 ). Otherwise get rid of count=1. Verify afterwards with cmp /dev/zero /dev/sdb (should say EOF on /dev/sdb assuming sdb is fully zero). – frostschutz Jan 27 '18 at 19:44
  • You'll find cat /dev/zero >/dev/sdb faster than dd. Really. – Chris Davies Jan 27 '18 at 22:09

1 Answers1

2
  1. dd would be slow in this instance.

    You could install pv (man page) with:

    yum install pv
    
  2. pv could be faster and I would suggest scrambling instead of zeroing, first, (if you are serious about the data erasure, that is):

    pv < /dev/urandom > /dev/sdX
    
  3. There is no need of checking if this has been done. In this instance, where we would be scrambling instead of zeroing, there is no way anyways.

  4. If you wish to zero the whole drive now, simply do:

    pv < /dev/zero > /dev/sdX
    
  5. If the drive has been zeroed, now you can check if it's really zeroed with:

    pv /dev/sdX | tr --squeeze-repeats "\000" "Z"
    

    Example output:

    1,00MiB 0:00:00 [ 202MiB/s] [=============================>] 100%            
    Z
    

    Noticed the one and only letter Z as the output? That's what you're looking for in here.

    Taken from https://superuser.com/a/559794/402107

  • Is there a source or otherwise some evidence for why dd with a reasonable block size would be any slower than pv? – Hashim Aziz Dec 01 '19 at 21:55