LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-12-2014, 03:30 PM   #1
oryan_dunn
Member
 
Registered: Sep 2002
Location: Auburn, IN
Distribution: Fedora/Red Hat/CentOS
Posts: 68

Rep: Reputation: 15
Starting shell dir when home dir is a symlink


My setup, home dirs are /users/%username%, /users is a symlink to /mnt/users.

When you start a shell locally, the shell starts in /mnt/users/%username%, $HOME is /users/%username% and if you cd ~, you are in /users/%username%.

If you ssh into the box, you start in ~ (pwd shows /users/%username%). It looks like local terminals are following the symlink. I could always add a cd ~ or similar to a startup script in my homedir, but I'd like to solve this globally. The issue is that /mnt/users/%username% paths are creaping into some programs (notably local eclipse installs).
 
Old 03-12-2014, 04:38 PM   #2
notKlaatu
Senior Member
 
Registered: Sep 2010
Location: Lawrence, New Zealand
Distribution: Slackware
Posts: 1,077

Rep: Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732Reputation: 732
Is there a reason you are symlinking home dirs? why not just define a user's homedir as /mnt/users/$USER when you add the user to your system? ie, `useradd --base-dir /mnt/users/ --create-home USERNAME`

Assuming you have your reasons, however, I am assuming you created your symlinks with `ln -s`
Try just `ln` instead.
 
Old 03-12-2014, 06:02 PM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
The shell remembers how it got to the current directory, and when you use the builtin pwd command or use the internal PWD shell variable it just displays that remembered path, which might include symlinks. The cd command (a shell builtin) also uses that remembered path, so "cd .." might not get you to the directory that is physically the parent of your current directory.

Any external program that starts in the current directory and uses ".." to refer to the parent will always get the physical parent directory. This can lead to confusion, as in your case, where "cd ../..; ls" would yield entirely different results from "ls ../..". Similarly, any program that uses the getcwd() system call will get the physical path from the root to the cwd, and no symlinks.

Instead of using a symlink, I suggest making /users a directory and bind-mounting /mnt/users there. In /etc/fstab it would look like this:
Code:
/mnt/users   /users   none   bind   0  0
The command to do that mount manually would be
Code:
mount --bind /mnt/users /users
Now everyone will see /users/USERNAME as a consistent path to the home directory, "cd ../.." will get you to the root directory and not /mnt, and getcwd() will return the "/users/USERNAME" path.

FWIW, on my own system the home directories are physically in /var/home which is bind-mounted to /home. I've been using it that way for years with no confusion occurring. Backup scripts do have to know not to descend into the /home mount point, but that's no different from avoiding other mount points when backing up a filesystem.

@notKlaatu -- Not even root is allowed to make a hard link to a directory. Many parts of the system make the tacit assumption that the directory structure is a tree, and hard linked directories would break that.

Last edited by rknichols; 03-12-2014 at 06:05 PM. Reason: added @notKlaatu
 
1 members found this post helpful.
Old 03-12-2014, 06:24 PM   #4
oryan_dunn
Member
 
Registered: Sep 2002
Location: Auburn, IN
Distribution: Fedora/Red Hat/CentOS
Posts: 68

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by rknichols View Post
The shell remembers how it got to the current directory, and when you use the builtin pwd command or use the internal PWD shell variable it just displays that remembered path, which might include symlinks. The cd command (a shell builtin) also uses that remembered path, so "cd .." might not get you to the directory that is physically the parent of your current directory.

Any external program that starts in the current directory and uses ".." to refer to the parent will always get the physical parent directory. This can lead to confusion, as in your case, where "cd ../..; ls" would yield entirely different results from "ls ../..". Similarly, any program that uses the getcwd() system call will get the physical path from the root to the cwd, and no symlinks.
You are spot on. I had never noticed that before. When I ssh in and bash shows me at my 'home' dir of ~, ls ../.. and cd ../..;ls do give different results.

I looked into it, pwd -P give the physical path; I bet bash uses the C getcwd() as you say and hence why it starts in /mnt/users/%username%

Quote:
Originally Posted by rknichols View Post
Instead of using a symlink, I suggest making /users a directory and bind-mounting /mnt/users there.
That sounds like an excelent solution. Does the bind mount have to appear after the actual mount to /mnt/users? It'll be no problem, just wondering if mount can sort things out.
 
Old 03-12-2014, 10:53 PM   #5
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Quote:
Originally Posted by oryan_dunn View Post
Does the bind mount have to appear after the actual mount to /mnt/users? It'll be no problem, just wondering if mount can sort things out.
I have to confess I've never really thought about that. I always just added it at the bottom of my /etc/fstab, which of course put it after the other mounts.
 
Old 03-14-2014, 12:41 PM   #6
oryan_dunn
Member
 
Registered: Sep 2002
Location: Auburn, IN
Distribution: Fedora/Red Hat/CentOS
Posts: 68

Original Poster
Rep: Reputation: 15
Well, from the command line, it works great. However, it doesn't appear to be working from fstab. I've tried putting the bind mount before and after the /mnt/users nfs mount. It looks like the bind mount is happening before the nfs mount of the /mnt/users, so /users is still pointing to the empty /mnt/users dir on the local machine instead of the remote mount. I'm pretty sure the fstab options are correct, since I can call
Code:
# mount /users
and the system bind mounts as you'd expect.

It seems like the nfs mount it taking too long and in either case of the bind mount appearing before or after the nfs mount in fstab, it gets mounted before the nfs mount.

Any ideas?
 
Old 03-14-2014, 01:07 PM   #7
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,783

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
You had not mentioned that NFS was involved, but indeed, that won't work with an NFS mount. Local filesystems get mounted first. NFS mounts come later. Actually, I'm a bit surprised that bind-mounts of NFS directories work at all.
 
Old 03-14-2014, 01:16 PM   #8
oryan_dunn
Member
 
Registered: Sep 2002
Location: Auburn, IN
Distribution: Fedora/Red Hat/CentOS
Posts: 68

Original Poster
Rep: Reputation: 15
My appologies. I'm looking into why the nfs mount was moved and whether we can just nfs mount in both places.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
copying files from home dir to another dir from another dir in a lower dir chomito44 Linux - General 5 10-19-2013 06:18 PM
adduser but no shell and no home dir ryedunn Linux - Newbie 7 09-05-2011 09:52 AM
Can't find .ssh dir in home dir bobby953 Linux - Newbie 5 03-09-2009 04:00 AM
Removing a Specific Dir From All /home Dir carlosinfl Linux - General 4 06-09-2008 01:08 PM
howto make a dir shared that is not in my home dir Schmurff Linux - Newbie 2 06-19-2004 07:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration