Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there an easy command that I can use to zero out the last 1MB of a hard drive?

For the start of the drive I would dd if=/dev/zero of=/dev/sdx bs=1M count=1. The seek option for dd looks promising, but does someone have an easy way to determine exactly how far I should seek?

I have a hardware RAID appliance, that stores some of the RAID configuration at the end of the drive. I need the RAID appliance to see the drives as un-configured, so I want to remove the RAID configuration without having to spend the time to do a full wipe of the drives. I have a dozen 2TB drives, and a full erase of all of those drives would take a long time.

share|improve this question
up vote 11 down vote accepted

The simplest way to get the size of the disk is with blockdev --getsz:

sudo -s
dd bs=512 if=/dev/zero of=/dev/sda count=2048 seek=$((`blockdev --getsz /dev/sda` - 2048))
share|improve this answer
Excellent, I knew there must be a tool that could get the size easily. – Zoredache May 30 '11 at 19:33

The size of every partition is available in /proc/partitions. The following command shows the size of sdx (in kB units):

awk '$4 == "sdx" {print $3}' </proc/partitions


dd if=/dev/zero of=/dev/sdx bs=1k count=1024 \
   seek=$(($(awk '$4 == "sdx" {print $3}' </proc/partitions) - 1024))
share|improve this answer

You can use dd and get the device size via fdisk:

dd if=/dev/zero of=/dev/sda bs=1k \
   seek=$(( (`fdisk -l /dev/sda | grep 'Disk /' | cut -d' ' -f 5` -1024*1024)/1024  )) count=1024

I am not using a blocksize of 1m to avoid rounding errors.

Alternatively, you could write a small C-program (or script) which invokes the lseek function with SEEK_END and a negative offset of 1mb and then call write.

share|improve this answer

You can get the number of sectors on the disk with hdparm -v /dev/sdx. Try seeking to number_of_sectors - 2048 (assuming 512 byte sectors).

share|improve this answer
hdparm seems handy, but how would I check the sector size? – Peter.O May 27 '11 at 14:16
/sys/block/sdx/queue/physical_block_size may give you the information but some newer disks play fast and loose with the sector size they report. It's probably better to read the label on the disk or look it up in the manufacturers data sheet. – Iain May 27 '11 at 14:41
Thanks.. I've just noticed that hdparm -I /dev/sda lists 2 "versions" of sector size: Logical and Physical. Is this what you mean by "fast-and-loose"? .... I jsut get that "feeling" that if anything is going to behave in such a way it could well be a RAID system.. – Peter.O May 27 '11 at 14:58
@red: I can't fid the reference now but I read somewhere that some drives with 4096 byte sectors will report to the system that they are 512byte and then deal wit the conversion internally. – Iain May 27 '11 at 15:53

Your Answer


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.