Solved Erase last few blocks of disk

Every now and then I run into this.
Trying to zero out the last few block of a disk to clear out any information or marker that might have been stored there.
dd if=/dev/zero of=/dev/ada0 skip=....
where the number to skip is a little less than what is shown for the total number of blocks for that particular drive.
However, this takes annoyingly long, even for a 200 GB drive, as dd seems to start walking through every single block from disk-start to whatever I said to skip, instead of jumping there. So zeroing the last few block this way is not faster than zeroing the entire disk.

Could anybody suggest a better way to zero out the last blocks of a disk?
 
Is there any difference if you specify block size using bs=4k or bigger as default blocksize of dd is 512b.
 
You are using a wrong operand "skip", because it is skipping input device (/dev/zero).

There are two options for your convenience:
Code:
     iseek=n  Seek on the input file n blocks.  This is synonymous with skip=n.
     oseek=n  Seek on the output file n blocks.  This is synonymous with seek=n.

So if you want to skip some blocks on the target device then you should use oseek= or seek=

dd()
Code:
     seek=n   Seek n blocks from the beginning of the output before copying.
              On non-tape devices, an lseek(2) operation is used.  Otherwise,
              existing blocks are read and the data discarded.  If the user
              does not have read permission for the tape, it is positioned
              using the tape ioctl(2) function calls.  If the seek operation
              is past the end of file, space from the current end of file to
              the specified offset is filled with blocks of NUL bytes.

     skip=n   Skip n blocks from the beginning of the input before copying.
              On input which supports seeks, an lseek(2) operation is used.
              Otherwise, input data is read and discarded.  For pipes, the
              correct number of bytes is read.  For all other devices, the
              correct number of blocks is read without distinguishing between
              a partial or complete block being read.

Also, you can use dd to save to a file few blocks which you are planning to erase, before and after erasing.
Using hd() you can review the saved blocks for checking the results.
 
You are using a wrong operand "skip", because it is skipping input device (/dev/zero).
Ooops.
You know, this is not the first time I mix up those two. Skip and seek.
Thanks for pointing this out! Would have taken me hours, maybe a day or two before realizing what I do wrong. :-(
 
  • Thanks
Reactions: im
Back
Top