Understanding how dd works

Patrick O'Callaghan pocallaghan at gmail.com
Wed Jun 25 16:29:46 UTC 2008


On Wed, 2008-06-25 at 11:02 -0500, Mikkel L. Ellertson wrote:
> Patrick O'Callaghan wrote:
> > On Wed, 2008-06-25 at 13:31 +0100, Dan Track wrote:
> >> Thanks for the heads up on this. If the data blocks don't have
> >> anything written into them, then what data is written into them when
> >> using dd? if I restore the dd image will the blocks then be in the
> >> same state i.e unwritten to?
> >>
> >> Also following on from this if I create a file using dd let's say 2GB,
> >> how does the filesystem know that all these blocks belong to the file
> >> myfile.img, and where is the information stored to say that a block
> >> has data written into it or not?
> > 
> > It's important to understand that this has nothing to do with 'dd', it's
> > simply how the Unix filesystem works, and since Linux is "culturally
> > derived" from Unix, it does the same thing. You would see the same
> > effect just by using 'cp' or even 'cat'.
> > 
> cp knows how to handle sparse files. From the cp man page:
> 
> By default, sparse SOURCE files are detected by a crude heuristic 
> and the corresponding DEST file is made sparse as well.  That is the 
> behavior selected by --sparse=auto. Specify --sparse=always to 
> create a sparse DEST file whenever the SOURCE file contains a long 
> enough sequence of zero bytes. Use --sparse=never to inhibit 
> creation of sparse files.
> 
> So I would think that cp would give him a good copy...

True. I've been using cp for more than 30 years so I hadn't looked at
the man page in the last decade or two :-)

poc




More information about the fedora-list mailing list