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.

Wednesday, August 15, 2012

Day Zero

The Linux Gazette used to have a feature in the Back Page section called 2 Cent Tips. They were small, fun little tricks, usually shell or command related, that made life easier for me. LG is largely defunct now, it seems, but I'm still finding lots of neat little tidbits of information I want to keep around for future reference. So here they are. My own 2 Cent Tips section, culled from the web, with direct references where possible. Satisfaction guaranteed or you can go do your own googling.