Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

migrated from stackoverflow.com Apr 8 '10 at 16:16

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 5 down vote accepted

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
share|improve this answer
1  
This accepted (?) answer blanks the last 512 bytes of the file while the question was about 512 kilobytes, which is quite larger. The command should be: dd if=/dev/zero of=$YOUR_DEV bs=512 seek=$(( $(blockdev --getsz $YOUR_DEV) - 1024 )) count=1024 –  jlliagre Aug 29 '13 at 22:47

Use the seek predicate to go to the end of the disk.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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