Jump to content

issues with the cp command


Recommended Posts

As some may have seen in another post in software I had a problem copying my home directory to another partition as part of a reorganizing my hd. Using cp -ax my system came to a halt as my / partition completely filled up. Specifically I cd'd to /home (Ihave four users there) and ran cp -ax * /newhome (newhome is the partition I am going to use for /home.

My question is how does cp work? I got out of my mess by using a blank section of my hd and booting in failsafe. There I used drakconf to set up partitions for /var and /tmp and drakconf blessedly moved everything from the /var and /tmp directories in my / partition. I have no idea how drakconf partitioning goes about moving things that is different than the cp command. I should add that after / filled up rebooting did not clear up any space.

As I still have a bit of moving around of files I'm worried that I will again have this problem. If /tmp is the problem my giving it its own partition may help.

Any help would be appreciated.

Link to comment
Share on other sites

Thanks. There are two reasons I chose to use cp: 1) I like to be sure everything is fine in the destination without losing the source so I want both, being conservative and maybe too much so, and most important 2) I'm setting up new /usr and /home partitions and while I'm logged in I need to work with the original ones. If I do it in failsafe I don't have to worry about /home and can edit /etc/fstab, but if /usr goes elsewhere what? I don't understand that one.

Link to comment
Share on other sites

I can give you two ways to do that. Using the cp command I would generally do:

 

# cp -pidRv /home/* /mnt/<new home partition mount point>/

 

The reasons for my "pidRv" flags:

 

-p Preserve the original files' owner, group, permissions ...

-R Copy directories recursively and do the right thing when objects

other than ordinary files or directories are encountered.

-i Prompt whether to overwrite existing regular destination files. (I do

this JUST IN CASE! you should start with a new blank partition and

then you'll never get prompted -- you could leave this out or use -f if

you're sure you want to overwrite stuff.)

-d, --no-dereference

Copy symbolic links as symbolic links rather than

copying the files that they point to, and preserve

hard links between source files in the copies.

-v, --verbose

Print the name of each file before copying it. (slows it

down a bit but I like to see it doing stuff rather than

wait blindly.)

 

I also do this as root because it is possible to have files that only can be read by root even in your home directory. If you try to copy them as an ordinary user, you will get an error message when such a file is encountered.

 

However, I find that using the tar command to do this is better than using the cp command. Using tar, you just cd to your home directory and run:

 

# tar -cf - . | (cd <path to destination_directory>; tar -xvf -)

 

This is a very old tar trick for copying a partition from one place to another. The first part(tar -cf .) creates a tar archive of your current directory. The "." at the end ensures that the current directory is recursively archived . That result is piped through to the stuff in parentheses which cds to your destination and extracts the archive just created. Tar is very good at getting everything just right re permissions, file ownership, links, etc. which is why I like it bvetter than cp.

 

You will have to set up new mount points for your new /home partition in fstab. This stuff is usually easier to do from a live cd like knoppix or kannotix. I do not like to try to copy /home from a running system as there may be changing temporary files that can cause problems. You can use the same technique for moving /var and /tmp but for those you will definitely have to be root. Both /var and /tmp have files only readable by root. Again, you will have a lot fewer problems by doing this from a live cd rather than from a running system.

Link to comment
Share on other sites

Thanks, pmpatrick. I had done the home switch (using cp -ax, the option -a is the same as -pdR by the way). I hadn't thought of a live cd, but will for /usr. My main question, which probably wasn't expressed too clearly, is about how the cp command can fill up my / partition. I assume there is an intermediate step from partition a to partition b that uses space in what was my / partition. I assumed it was /tmp, but I have no idea whether that is true. So my thought is cp a b involves a->intermediate->b, but I don't know what intermediate is. I do know that in my case it ate up all the available space in /.

Link to comment
Share on other sites

I would think it would have to be something written to /tmp or swap but I think the main problem is trying to copy a running system. It may have to write a snapshot somewhere and then copy over. This is all speculation of course. I can tell you I've never had that happen while copying with a live cd.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...