Saturday, August 18, 2012

Never copy with just 'cp'

Something from way back on openbsd-misc@ from Otto Moerbeek. I've long ago lost the reference, unfortunately:
On Mon, 6 Dec 2004, Dave Feustel wrote:
    My original /usr partition is not big enough to hold OpenBSD source, so I have added another disk to which I have copied (cp -Rp /usr /mnt) and then have untarred source gz files from the 3.6 cdrom to /mnt. My plan is to mount this disk at /usr, replacing the partition which contains the original /usr. I noticed that the copied /usr partition is somewhat larger than the original. Is there anything else I need to do before I change the /usr entry in /etc/fstab?
Never copy just with cp -Rp , use:
       cd /usr
       pax -rw -pe . /mnt
cp will mangle hard links, soft links, device nodes and what more.
The (possibly surprising) thing to remember here is Otto's example assumes you are following his steps as outlined. Yes, both of them. pax will recreate paths all relative to . (read: here) in /mnt so if for some reason you need to be in different directories, you'll need to remember the same rules you have to remember for, say, rsync which has a similar habit of confusing me with path interpretation and giving me more nested levels than I intended.

No comments: