Re: dd if=/dev/zero of=/dev/hda

Top Page
Attachments:
Message as email
+ (text/plain)
+ (application/pgp-signature)
Delete this message
Reply to this message
Author: Bill Jonas
Date:  
To: plug-discuss
Subject: Re: dd if=/dev/zero of=/dev/hda
On Sat, Jun 26, 2004 at 09:29:40PM -0700, plug wrote:
> entire drive, several times over. With reiserfs's default block size of
> 4096 bytes, that'd be about 347.3 gigabytes... I think it's safe to say
> this drive is zeroed. :)


You're off by a factor of eight. The "blocks" that are reported have
nothing to do with the block size of the filesystem. From the man page:

       [dd] reads the input one block at a time, using the specified
       input block size (the default is 512 bytes).


So that means that 84800992 blocks translates to roughly 40 gigabytes,
or about half the disk.

One thing that you can do to speed it up (tremendously) is to specify a
larger block size. A 512-byte block is inefficient on modern hardware.
First, you read 512 bytes, then you write 512 bytes. Then you read
*another* 512 bytes, then you write *another* 512 bytes. What I prefer
to do is to specify a block size (the "bs=" option) equal to the drive's
buffer size, which for most drives today would be two megabytes
("bs=2M"). If you're not sure how much you have, either look in cat
/proc/ide/hda/cache or just specify the command as "dd if=/dev/zero
of=/dev/hda bs=`cat /proc/ide/hda/cache`k".

Rationale: With modern hardware, 512 bytes is quite inefficient. It's
better to just give it a large chunk all at once and let the hardware do
what it was designed to do. I've tried ten-megabyte block sizes, but
that caused a lot of thrashing on my system, and I'm running with 512MB
of RAM. I figure that by using a block size equal to the cache size,
especially when you're taking input from /dev/zero (which takes almost
no time to read), you're filling up the cache, fetching another block as
it starts writing, and trickling it into the cache as the cache empties
onto the disk.

I have used this method when reading a partition to make an image ("dd
if=/dev/hda2 bs=2M |gzip -cd >filename.tar.gz") of a partition for
backup purposes, and it's sped up the operation by a factor of what
seems like an integer multiple.

-- 
Bill Jonas    *        *    http://www.billjonas.com/
"It's a dangerous business, Frodo, going out your front door.  You step
into the Road,  and if you don't keep your feet,  there  is  no knowing
where you might be swept off to."  --  Bilbo Baggins