1837897 Members
3575 Online
110123 Solutions
New Discussion

Re: Linking directories

 
SOLVED
Go to solution
Amiel Tutolo
Frequent Advisor

Linking directories

I am going to create a new /usr called /usr so that I can move some of the directories there. My question is how do I link the directories correctly? Do you copy the files first, link the directories and then remove the ones you copied? I just need some steps to follow. I have done this in a lab setting but not in the real world. Thanks
Live, love and laugh
16 REPLIES 16
Steven E. Protter
Exalted Contributor
Solution

Re: Linking directories

move the files first then do a hard or soft link with the ln command

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
A. Clay Stephenson
Acclaimed Contributor

Re: Linking directories

Typically, /usr is a filesystem rather than a simple directory so that you would create a new filesystem (on a new logical volume), mount the new filesystem as /usr2, cpio all the files in /usr to the new /usr2. I would then alter /etc/fstab and mount the new filesystem as /usr.

If all you want to do is mount some directories (possibly in a different filesystem) under /usr then the key to this is the symbolic (soft) link.

e.g.


ln -s /newfs/newdir /usr/flea
ln -s /newfs2/newdir2 /usr/dog

Now /usr/dog will point to /newfs2/newdir2 and this redirection will be invisible to the application.
If it ain't broke, I can fix that.
Sridhar Bhaskarla
Honored Contributor

Re: Linking directories

Hi,

If this new filesystem is going to be part of another volume group, then I would suggest you to pay attention to the directories that you would like to link. Typically you may want to keep bin,lib,sbin etc., in /usr as during the external storage maintaince, you will have the basic /usr functionality available. If you have any software like backup etc, you can probably create them under new filesystem and create softlinks.

Create a newfilesystem and mount it as /usr1
Make sure you have the corresponding entry in /etc/fstab.

#cp -Rp /usr/local /usr1/local
#du -sk /usr1/local

once contents are properly copied, create links

#rm -rf /usr/local
#ln -s /usr1/local /usr/local

YOu better do it in single user mode so that you will not affect the OS or application.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Amiel Tutolo
Frequent Advisor

Re: Linking directories

Ok. In my question I said /usr twice. What I meant was a a new fs called /usr2. So I guess I would create filesystem /usr2, copy the directories and files I want from /usr, then using the ln command do the following
ln /usr/xxx /usr/xxx
Am I correct or way off?
Live, love and laugh
Jeff Schussele
Honored Contributor

Re: Linking directories

Hi,

You simply can't have TWO filesystems mounted to /usr at the same time.

If I understand you correctly you want to move dirs *under* /usr to another filesystem. In that case, I think the proper way to do this is to fbackup the data in those dirs & then delete the files in the filesystems in those dirs. Beforehand you would have created the new LV/FS structure & now mount them to /usr/dir1, /usr/dir2 & frecover that data back into these newly created filesystems.

I guess you could also temp mount the new filesystems to some other location, copy the data from /usr/dir1, /usr/dir2, etc to /usr/temp1, /usr/temp2, etc. THEN empty /usr/dir1, /usr/dir2, etc. & umount /usr/temp1, /usr/temp2, etc & then remount them to the newly emptied /usr/dir1, /usr/dir2, etc.

In both scenarios don't forget to edit /etc/fstab for these new mounts.

My 2 cents,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Sridhar Bhaskarla
Honored Contributor

Re: Linking directories

HI,

No. You cannot have two /usr filesystems. So, linking from /usr to another /usr is not possible.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
Amiel Tutolo
Frequent Advisor

Re: Linking directories

OK. In my second post I said .usr twice again. I need skinnier fingers. I meant that the link command chould look like this:
ln /usr/xxx /usr2/xxx

Sorry if I am confusing nayone. I don't want to screw this up and have to go to an ignite tape.
Live, love and laugh
Sridhar Bhaskarla
Honored Contributor

Re: Linking directories

Hi,

Use 'ln -s' as indicated

ln -s source destination

To create a link from /usr1/local to /usr/local, you would run the command

ln -s /usr1/local /usr/local

ll /usr/local

lrwxr-xr-x 1 root sys 14 Jan 23 16:03 /usr/local -> /usr1/local

As the man page says, ln does not create hardlinks between filesystems.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
A. Clay Stephenson
Acclaimed Contributor

Re: Linking directories

No, you blew it again:

ln /usr/xxx /usr2/xxx
should be:
ln -s /usr2/xxx /usr/xxx

That will have the effect of whenever you cd to /usr/xxx, you will actually cd to /usr2/xxx. Man ls for details and pay particular attention to the -s option.

As an aside, it is not required than /usr be on the boot disk or even in vg00 for that matter. The only LVOL's which must be on the boot disk are /, /stand, and primary swap. I wouldn't want to move /usr out of vg00 but it's not a requirement.
If it ain't broke, I can fix that.
Michael Schulte zur Sur
Honored Contributor

Re: Linking directories

Hi,

may I ask you, why you want to move things out of /usr? It looks to me, you are running out of space there, right? Be careful anyway, what you put there. You certainly don't want the machine to get stuck at bottup.

Michael
Amiel Tutolo
Frequent Advisor

Re: Linking directories

I am running low on space and I don't see anything I can just remove. I was going to move directories like old, examples, and openv to new filesystem (usr2) and then link them back to usr. If I can get some downtime I was just going to extend the filesystem. It doesn't seem to grow much except for when out DBA forgets about cleaning out his mail. Of course I just go in and delete it all.
Live, love and laugh
James A. Donovan
Honored Contributor

Re: Linking directories

As far as /usr/openv is concerned, I've moved the netbackup files under /opt (where they belong, dammit! ;-)), and created a link under /usr.

So if you have the room under /opt, I would suggest...

# mv /usr/openv /opt
# ln -s /opt/openv /usr/.

Netbackup still runs prefectly fine, and the netbackup logs don't fill up my /usr filesystem.

Remember, wherever you go, there you are...
Michael Schulte zur Sur
Honored Contributor

Re: Linking directories

Hi,

can you post as attachment du -k /usr so we can see, where space is used?

Michael
A. Clay Stephenson
Acclaimed Contributor

Re: Linking directories

/usr is one of those filesystems that should remain all but fixed in size once a system has stabilized. Your mention of mail is a glaring problem. There should be a symbolic link to /var/mail from /usr/mail so that all transient activity (like mail) actually occurs in /var. Likewise, /usr/tmp should be be soft-linked to /var/tmp.
If it ain't broke, I can fix that.
Amiel Tutolo
Frequent Advisor

Re: Linking directories

Attached is the du -k /usr. Thanks for everyones help. I will assign points by Monday.
Live, love and laugh
Michael Schulte zur Sur
Honored Contributor

Re: Linking directories

Hi,

do you really need chinese, korean and japanese fonts? They gobble up a lot of space.

Michael