compressed HDD image using dd...clearing unused blocks

Oliver Fromme olli at lurza.secnetix.de
Fri Jul 13 12:03:03 UTC 2007


Paul Schenkeveld wrote:
 > Michael Eubanks wrote:
 > Paul Schenkeveld wrote:
 > > > What about:
 > > > 
 > > >   # dd < /dev/zero > BIG_EMPTY_FILE bs=128k
 > > >   # rm BIG_EMPTY_FILE
 > > > 
 > > > Comes close to what you want, only a couple of
 > > > indirect blocks are
 > > > not zeroed this way but the majority of unused
 > > > blocks will be.
 > > 
 > > ...snip...
 > > [...]
 > 
 > The bs=128k is just for speed.  Dd will write an incomplete block at the
 > end of the file to fill up just whatever space you need.  If you fear
 > system instability, run this in single user mode.
 > 
 > Oh, do a sync and wait a while between the dd and the rm to allow the
 > kernel some time to flush out blocks to disk, otherwise you've only
 > efficiently zeroed out the buffer cache :-)

Are you sure?  ISTR once I wrote a big file to a floppy
which didn't fit.  I got an error message and removed
the incomplete file, but the floppy drive continued to
write the blocks from the cache.

I think the buffer cache works on block level, not on
file level, so the syncing and waiting shouldn't be
necessary.  The zeroed data blocks schould still be
written to disk, even after the directory entry has
been unlinked.

Besides, the buffer cache is certainly _much_ smaller
than the hard disk in question, so the majority of
blocks has already been zeroed on disk when the dd
command finishes.

Best regards
   Oliver

-- 
Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M.
Handelsregister: Registergericht Muenchen, HRA 74606,  Geschäftsfuehrung:
secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün-
chen, HRB 125758,  Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart

FreeBSD-Dienstleistungen, -Produkte und mehr:  http://www.secnetix.de/bsd

"Perl will consistently give you what you want,
unless what you want is consistency."
        -- Larry Wall


More information about the freebsd-chat mailing list