How best to copy the entire contents of one partition to another?

Dale Farnsworth dale at farnsworth.org
Sun Jan 8 10:02:58 MST 2006


In article <43C13CF4.8060805 at shubes.net> Eric write:
> > dd will copy the full partition, block by block, rather than
> > copying individual files.  It's almost always more appropriate to do
> > "cp -a", unless fsck detects significant filesystem structure damage.
> 
> Why is that so? (please expound a bit)

I'll try.

Advantages of "cp -a":
	1. cp only copies allocated files, so if you have used 10GB of
	   a 100GB partition, cp copies only the 10GB.

	2. When copying to a newly created filesystem, the resulting
	   files are contiguous.  In the old days when fragmentation
	   was more of a problem, copying to a new FS was a common
	   defragmentation technique.

	3. Source and destination filesystems can be different sizes,
	   as long as the destination FS is large enough to contain
	   the files.

Advantages of dd (used as partition copy):
	1. Copies the raw partition blocks, so it works even when
	   the filesystem has so much damage that cp can't work.
	   It can backup a damaged filesystem before you attempt
	   to repair it.

	2. Can read and write in large contiguous blocks, which can
	   be faster than copying individual files.  This benefit
	   is less than it used to be, because Linux is better
	   than before at keeping files contiguous and coalescing
	   disk writes.

	3. Reads/writes every block of the FS, so you can check for
	   bad blocks.

	4. Can be used to copy a partition with an unsupported
	   filesystem type, e.g. NTFS.

I'll also mention the -x option to cp.  It's particularly helpful
when backing up the root filesystem.  "cp -ax / /mnt/rootbackup"
will back up only files from the root partition, even though other
filesystems are mounted.

-Dale


More information about the PLUG-discuss mailing list