Copy filesystems / disk trees
From MEPIS Documentation Wiki
How do you copy a directory tree or filesystem and preserve ownership and permissions? There are a number of ways that this can be accomplished, with varying degrees of complexity. Assume for the sake of this tip that we want to copy the contents of /mnt/hda1 to /mnt/hda5. Each of the following commands will do the trick.
| Command | Example |
|---|---|
| cp | cp -Rp /mnt/hda1 /mnt/hda5 |
| rsync | rsync -av /mnt/hda1/ /mnt/hda5/ |
| tar | (cd /mnt/hda1; tar tf - .) | (cd /mnt/hda5; tar xvf -) |
| cpio | (cd /mnt/hda1; find . -depth -print | cpio -oac) | (cd /mnt/hda5; cpio -idmuv) |
The cp command is the simpliest. It will copy the files and preserve the permissions and ownership.
The rsync command is probably the best. It can be used to mirror a drive. If you make some changes to part of the files and then re-run it, it will only copy the changes.
Both tar and cpio are the most difficult to understand, but are more flexible.
Important: to copy your current working partition it is better to boot into the Live CD and execute the command from there. Hot cloning is possible, but not recommended.

