Jump to content

Moving /usr - how to copy everything?


ffrr
 Share

Recommended Posts

Hi,

 

I am attempting to move /usr to another hard drive. I have partitioned and formatted it, and mounted it to /mnt/hdb1moount directory. Now I want to copy /usr to it, but my unix skills are lacking. How to I copy all the files, including hidden files, and preserve permissions and ownership?

 

I tried cp -p but that doesn seem to see hidden files. Also I worry about any symbolic links etc.

 

Also, after the copy, I intend to mount it to /usr and put an entry in fstab to automount it. I have read some instructions on the net and I think I should be fine, but one thing I read, I dont understand fully. Someone said that if you want other stuff moved as well, say /home , then you can create /usr and /home directories on the new drive and put the files in them, but then mount the drive to the root. Now I thought that if you mounted to an existing directory, all the existing files there would become unaccessible. Is root different?

 

[moved from Installing Mandrake by spinynorman]

Link to comment
Share on other sites

Actually, I have used diskdrake successfully for this sort of thing. It will make a new partition, and then ask if you want to move all the data from the existing to the new! Pretty cool!

 

Someone will remember the command line stuff. Or you could Google.

Link to comment
Share on other sites

Actually, I have used diskdrake successfully for this sort of thing. It will make a new partition, and then ask if you want to move all the data from the existing to the new! Pretty cool!

 

Someone will remember the command line stuff. Or you could Google.

 

I don't know what diskdrake is, but if it is the program that runs when you select partitions from the Mandrake config console, that's what I used to partition the disk. I noticed that it offered to create it with the mount point /usr, but didn't realise it would have copied the files over, so I deleted the mount point field and just partitioned it, and mounted it later by hand.

 

I did a lot of googling, but it was hard to get specific with the query. What I did find was a reference to a program called filerunner, so I installed that, and managed to copy the /usr files using that. I now have the new drive mounted to /usr, an entry in fstab, and it reboots correctly using the new drive !!!

 

The only question I have left is whether I can put multiple subdirectories on the new drive ( like /usr /hom ) and then mount it to root (as suggested in a message I found with google)

Link to comment
Share on other sites

OK, so I set up two test directories test and test2.

- I put file fred in test

- I create suddirectory test/.stuff

- I put file freddy in test/.stuff

 

I issue the command cp -pax test/* test2

 

then I issue the command ls -a test2

 

I see ./ ../ fred

 

if I issue the command ls -a test

 

I get ./ ../ fred .stuff

 

 

It isnt copying the hidden files in test !

Link to comment
Share on other sites

Monday 14/03/05 - 12:03
~ --:mkdir test
~ --:mkdir test2
~ --:touch test/.hiddenfile
~ --:mkdir test/sub/
~ --:touch test/sub/.hiddenfile2
~ --:cp -a test/* test2/
~ --:ls -a test2/
.  ..  sub
~ --:ls -a test2/sub/
.  ..  .hiddenfile2
~ --:rm -rf test2/
~ --:mkdir test2
~ --:cp -a test test2/
~ --:ls test2/test/ -a
.  ..  .hiddenfile  sub

 

When you do a cp /home/iphitus/* it will only copy the visible files in /home/iphitus/. However hidden files in subdirectories *are* copied.

 

When I have copied partitions, I have booted to a live cd, made dirs /mdkhome and mounted my home partition there and done "cp -a /mdkhome /mnt/backup"

 

Doing it that way has always got all the files, like you can see above, I copied the whole test folder into test2 and it worked.

 

Cannonfodder: -a includes p already, and as for x

      -x, --one-file-system

              stay on this file system

what does it do?

 

iphitus

Edited by iphitus
Link to comment
Share on other sites

When you do a cp /home/iphitus/* it will only copy the visible files in /home/iphitus/. However hidden files in subdirectories *are* copied.

 

When I have copied partitions, I have booted to a live cd, made dirs /mdkhome and mounted my home partition there and done "cp -a /mdkhome /mnt/backup"

 

Doing it that way has always got all the files, like you can see above, I copied the whole test folder into test2 and it worked.

 

 

Yes, thanks for that. I see the subtle difference. I actually tried cp -a test/.* but the .* matches .. and traverses up one level causing all sorts of mess :D

 

Thanks to everyone for the help.

Link to comment
Share on other sites

In my opinion, the best way to replicate a directory tree (or even more than that), is using tar:

# (cd /source/parent/ && tar cf - things.to.replicate) | (cd /destination/folder/ && tar xpf -)

"things.to.replicate" can be a list of files and/or directories, or even a simple dot (.) for duplicating the whole current directory (current being "/source/parent/" here).

 

Yves.

Link to comment
Share on other sites

In my opinion, the best way to replicate a directory tree (or even more than that), is using tar:

# (cd /source/parent/ && tar cf - things.to.replicate) | (cd /destination/folder/ && tar xpf -)

"things.to.replicate" can be a list of files and/or directories, or even a simple dot (.) for duplicating the whole current directory (current being "/source/parent/" here).

 

Yves.

 

Agreed :D for a few variatins like :

tar cf - . | (cd /mnt/$TARGET && tar xBf -)

 

 

(don't miss the full stop either)

 

 

unix power tools

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...