ffrr Posted March 12, 2005 Report Share Posted March 12, 2005 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] Quote Link to comment Share on other sites More sharing options...
Ixthusdan Posted March 13, 2005 Report Share Posted March 13, 2005 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. Quote Link to comment Share on other sites More sharing options...
pmpatrick Posted March 13, 2005 Report Share Posted March 13, 2005 Try: cp -pidRv /old_drive/* /new_drive/ Quote Link to comment Share on other sites More sharing options...
ffrr Posted March 13, 2005 Author Report Share Posted March 13, 2005 Try: cp -pidRv /old_drive/* /new_drive/ <{POST_SNAPBACK}> That doesn't seem to get the hidden files. Quote Link to comment Share on other sites More sharing options...
ffrr Posted March 13, 2005 Author Report Share Posted March 13, 2005 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. <{POST_SNAPBACK}> 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) Quote Link to comment Share on other sites More sharing options...
polemicz Posted March 13, 2005 Report Share Posted March 13, 2005 should work using the a option with cp, i.e. cp -a. Quote Link to comment Share on other sites More sharing options...
ffrr Posted March 13, 2005 Author Report Share Posted March 13, 2005 should work using the a option with cp, i.e. cp -a. <{POST_SNAPBACK}> No it leaves out all the stuff starting with a . (the stuff normall hidden, that doesn show up with ls, only with ls -a) Quote Link to comment Share on other sites More sharing options...
iphitus Posted March 13, 2005 Report Share Posted March 13, 2005 (edited) I have done this successfully with cp -a multiple times, with my /home /usr and / partitions. It does get all the hidden files. Edited March 13, 2005 by iphitus Quote Link to comment Share on other sites More sharing options...
Cannonfodder Posted March 13, 2005 Report Share Posted March 13, 2005 I have done this successfully with cp -a multiple times, with my /home /usr and / partitions. It does get all the hidden files. <{POST_SNAPBACK}> Best way I know of is cp -pax (easy to remember yeah? pax roman :) Quote Link to comment Share on other sites More sharing options...
ffrr Posted March 14, 2005 Author Report Share Posted March 14, 2005 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 ! Quote Link to comment Share on other sites More sharing options...
iphitus Posted March 14, 2005 Report Share Posted March 14, 2005 (edited) 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 March 14, 2005 by iphitus Quote Link to comment Share on other sites More sharing options...
ffrr Posted March 14, 2005 Author Report Share Posted March 14, 2005 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. Quote Link to comment Share on other sites More sharing options...
Cannonfodder Posted March 14, 2005 Report Share Posted March 14, 2005 iphitus, I think it means not to follow symbolic links out of the current filing system (top of my head) Quote Link to comment Share on other sites More sharing options...
theYinYeti Posted March 14, 2005 Report Share Posted March 14, 2005 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. Quote Link to comment Share on other sites More sharing options...
Gowator Posted March 14, 2005 Report Share Posted March 14, 2005 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. <{POST_SNAPBACK}> Agreed :D for a few variatins like : tar cf - . | (cd /mnt/$TARGET && tar xBf -) (don't miss the full stop either) unix power tools Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.