Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help moving directories 1

Status
Not open for further replies.

JustKIDn

MIS
May 6, 2002
386
US
Hi All,

I've setup a SuSE linux pc for my kids. All is good.

I need to start adding educational programs but /dev/hda is going to be getting rather full.

It seems that most programs get installed in the /usr directory. So I want to add a new drive and move the /usr directory on to it.

So my questions are;

Is there anything I should watch out for?

Can I just install the drive and move the directory?

Do I need to add /usr to fstab?

What method of moving files should I use to maintain user and group status associated with each file/directory?

Did I miss anything?

Thanks!

tgus

____________________________
Families can be together forever...
 
Why do through all the trouble of moving /usr? I'd just mount the new drive as /usr2, install the software there, and edit my PATH settings.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks sleipnir,
But don't a lot of programs automatically install parts into the /usr directory without asking? How can I over-ride that?

RhythmAce,
I might like to consider LVM for any added drives. But I worry about attaching multiple drives together that contains /boot and /. If something goes wrong with a drive sometime, I might never be able to boot and recover.

tgus

____________________________
Families can be together forever...
 
This is my personal preference. Keep all your "system" stuff on the main drive. Put your /home on the second drive. I keep all my big stuff in my ~/ dir, along with all the things I want to have survive a fresh installation of Linux (hey, download an .iso, burn, install a new Linux, it's a weekend thing). That leaves you more room for /usr and others on the first/main drive.

Directly to your question, install new drive, mount it (say 'mount /dev/hdb1 /mnt' after formatting it), then 'cp -rp /usr /mnt' (not sure about the -rp, but you need recursive and preserve permissions, no linux system to test on right now). I know 'cp' can do it. If not, 'tar' can (using 'tar -cpf usr.tar /usr' then untar it with 'tar xpf usr.tar /mnt') in the same situation I described above).

Hope that helps.

----
JBR
 
Thanks JBR,

I used;

cp -v -r -p all /usr/* /usr2

That seems to be doing it. I haven't checked it yet, it's still working.

Is there a tool I can use to compare /usr to /usr2 when it's done to verify that everything is the same?



tgus

____________________________
Families can be together forever...
 
The problem with just copying everything is that most of the programs probably hard-coded locations of configuration, data, etc. files as being in /usr.

For example, the code for a web browser, when trying to read its bookmarks file, might look like [tt]fopen("/usr/share/browser/bookmarks.bmk", "r")[/tt].

When this is the case, simply moving everything won't help much. Even though the bookmarks file has changed location, the web browser hasn't changed where it looks for the file.

The only reliable way to "move" the stuff to a different location in the filesystem is to get the source packages (maybe on your installation CDs, otherwise check rpmfind.net) and rebuild the programs to live in a different prefix.

Yes, that's annoying and there should be a better way to do it. I'm working on a solution, actually, but until it exists and is usable, you'll just have to do it the hard way (or use LVM).

As an alternative, you could move everything over, then make /usr a symlink to /usr2. That should work, since programs will still look for their stuff in /usr, which will just be /usr2. However, there's probably some reason that would just end up breaking everything, so use with caution.
 
Hi,

I have successfully copied everything from /usr to /usr2.

Using 'du' both directories appear to be the same size; 1.1 GB.

Now I would like to 'compare' all the files and directories to verify that permissions and symbolic links are still intact.

Once I've done that, I will rename /usr to something like /usr-old, and rename /usr2 to /usr. chipperMDW, that should eliminate your concerns, right? That's been my plan from the start anyway.

I'm still looking. Is there a utility that can compare files and directories? If I was using windo$e, I would just use Total Commander (formally Windows Commander).

BTW: A command line utility is just fine with me! I won't need all that GUI stuff for this project.

Thanks for all the comments!

tgus

____________________________
Families can be together forever...
 
If you move to / and call find, to find in the current directory './' every symbolic link '-lname' which matches the pattern '*usr*', you may find out, if there is any symbolic link to '/usr/'.
Code:
find ./ -lname *usr*

If there is a link
Code:
/usr/local/share/man/foo.1
which points to
Code:
../de/foo.1
The link will still work on /usr2/, and the find will not find it (which is correct).

If all the links are okay, and the 'du' is reporting the same size, I would assume them to be equal.

I guess you HAVE to edit your fstab.
 
> Once I've done that, I will rename /usr to something like /usr-old, and rename /usr2 to /usr. chipperMDW, that should eliminate your concerns, right?

Yup, that'll work.
 

Well, I finally did a manual compare at random.

The files I checked were correct for permissions, owner and group info.

I thought about using 'diff', but I couldn't prove that it would compare owner and group info.
Also 'cmp', but it didn't look like it would do it either.

I was able to rename the directories and update the /etc/fstab file.
It would still be nice to know if there's a way to compare files for ownership etc.

Thanks for the help and support.


tgus

____________________________
Families can be together forever...
 
One possible way to make that comparison would be to tar both subtrees up and then compare the tar files; a tar file contains info on owner, group, and permissions.

However, I don't know enough about the tar format to guarantee that would work. Maybe try it with some smaller test trees first.
 
Another possibility would be, to make a 'ls -la', (how to include subdirs?) and pipe the output to a file, for both, usr and usr2.
Then compare both files.

With find - again - you'll get it done:
Code:
find /usr -name * -exec -ls -la {} \; > usr.lst
find /usr2 -name * -exec -ls -la {} \; > usr2.lst
diff usr.lst usr2.lst

Instead of '>' you need the 'bigger-sign' I don't know whether this will be displayed the right way...
... tested: is not displayed right...
 
chipperMDW: Fine- sometimes life is so easy!
-R - off course.

But how did ya enter that 'greater than'-sign in this thread?

Of course your -R is worth an asterix...
 
> how did ya enter that 'greater than'-sign

Just typed it :)

When you enter text in the message box, it does the &gt stuff for you automatically when it converts it to HTML... at least, it does for me.
 
>>>Now I know it myself<<<

Had a fresh kde3.1 and didn't set my keyboard.

&gt; did not work.
 
How about diff -r for a recursive directory comparison.

Also, using bash or ksh or zsh, this:

find /usr -name * -exec -ls -la {} \; &gt; usr.lst
find /usr2 -name * -exec -ls -la {} \; &gt; usr2.lst
diff usr.lst usr2.lst

can be written as:

diff <( find /usr -name * -exec -ls -la {} \; ) <( /usr2 -name * -exec -ls -la {} \; )

It's called process substitution and it rocks.

But why are you even using find? Why not 'ls -laR' for a recursive ls? And I think you need to escape the asterisk in your find, otherwise the shell will expand it.

 
I didn't know the -R switch, and introduced 'find' as a workaround.
Of course, with 'ls -laR' you don't need 'find'.
 
ericbrunson,

I looked into using diff, but I couldn't find anything about it that would verify uid, gid and/or permissions.

So I think diff -r will verify all the files exist, but I'm not sure it would check for uid or gid or permissions.

I did a random manual check and everything seems fine.

Since Linux is a multiuser and Networking OS, wouldn't it seem natural that it would have an easy way to verify certain attributes of files after they've been moved or copied?

tgus

____________________________
Families can be together forever...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top