Which way is the fastest to `dd` to the last 512 kilobytes of disk

ddunix

I have a 512G disk and I want to clear the last 512k bytes at the end of the disk.

I usually clear it by dd if=/dev/zero of=/dev/da0 the whole disk.

Which way is the fastest to do this operation?

Best Answer

As already pointed out, dd accepts the seek=BLOCKS parameter, which skips BLOCKS blocks in the output file.

Now you need to know the exact size of the disk, if you want to write the last 512kB. On linux, you can use the blockdev --getsz DEVICE command to get the size, in units of 512B.

So the command-line becomes something like:

dd if=/dev/zero of=$YOUR_DEV bs=512 seek=$(( $(blockdev --getsz $YOUR_DEV) - 1 )) count=1
Related Question