LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to integrate /home from a separate partition into existing filesystem? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-integrate-home-from-a-separate-partition-into-existing-filesystem-4175590823/)

fanoflq 10-05-2016 12:17 PM

How to integrate /home from a separate partition into existing filesystem?
 
How to integrate /home from separate partitions or devices into existing filesystem?

Scenario:

1) Have one or more separate partitions for /home.
And each partition contains one or more user directory.
E.g.
In sda10, /home with /user10-1, /user10-2, ....
In sda11, /home with /user11-1, /user11-2, ....

2) We have a root filesytem, on a new installed or an existing OS.
Obviously this OS already has a /home folder.

Questions:
a) If I mount sda10 and sda11 to root filesystem's /home directory, I would have conflicts.
So I would just mount each subdrectories (/user10-1, /user10-2, .... ) from sda10 and sda11 to root filesystem's /home directory.
Meaning create mount points of same names and mount those subdirectories from separate partitions under /home/<user_name>.

Is there a better way to do this?

b) Have done part a) above, the OS still does not know those newly mounted user directories in /home/<user_name> belongs to specific users.

So next I would create account for these user sub directories with same user account names.

When I create user accounts, I would expect OS to possibly delete those existing same name user subdirectories when the OS tried to create same directories for the new user account?

Is this likely and how do I deal with this deletion scenario?

How to configure OS to recognize such user subdirectories as
belonging to corresponding user such that when user signs in,
that subfolder would be automatically assigned to the appropriate user?


Thank you.

keefaz 10-05-2016 12:45 PM

First set your partition mountpoint in /etc/fstab eg:
Code:

/dev/sda10        /home1      ext4        defaults    1
/dev/sda11        /home2      ext4        defaults    1

Code:

mkdir /home1 /home2
mount /home1
mount /home2

It's just an example, you can use any name you want, and have to set correct filesystems accordingly
then when adding new users, you use the -b option for useradd
Code:

useradd -b /home1 -g <group> -u <uid> user10-1
useradd -b /home2 -g <group> -u <uid> user11-1

Edit:
It's possible to use bind mount also
Code:

mkdir -p /srv/hd1
mkdir -p /srv/hd2
mkdir /home/user10-1 /home/user11-1

Then in /etc/fstab
Code:

/dev/sda10        /srv/hd1      ext4        defaults    1
/dev/sda11        /srv/hd2      ext4        defaults    1
/srv/hd1/home/user10-1  /home/user10-1    none      bind
/srv/hd2/home/user11-1  /home/user11-1    none      bind
...

In this case all users have home dirs under /home

fanoflq 10-05-2016 01:20 PM

@keefaz:

Thank you!

IsaacKuo 10-05-2016 02:45 PM

I was going to suggest the bind mount option, but I'm happy to learn about the other method!

I will note one thing that does NOT work. If you try to use symbolic links (instead of bind mounts) in /home, then the symlink to a user's home directory at another location will NOT work. I don't know exactly why, I just know that when I tried it before it failed miserably...at least when trying to log in to a GUI.

fanoflq 10-07-2016 07:00 AM

@IsaacKuo:

What is Yahoo mechdan?

IsaacKuo 10-07-2016 06:57 PM

Quote:

Originally Posted by fanoflq (Post 5615002)
@IsaacKuo:

What is Yahoo mechdan?

That's my Yahoo account name, if you want to IM me. However, my IM info is years out of date. I haven't logged into my ICQ account in years, and Google+ IM is the only one which will likely get my attention.

MadeInGermany 10-08-2016 09:03 PM

In big environments you want every user as /home/user in the passwd.
If your physical storage path is different you need a mapping.
Having bind mounts in fstab is one solution.
The Sun Microsystems solution was automounter, using an auto.home (later auto_home) map.
Code:

# cat /etc/auto.master
/home auto.home
# cat /etc/auto.home
user1 server1:/export/home/home1/user1
user2 server1:/export/home/home2/user2

This is NFS syntax. It makes most sense if you have shared home directories on many computers.
The auto.home map (and even the auto.master) can be in NIS (or NIS+ or LDAP), as a means to centralize the administration of auto.home. Otherwise another configuration management must provide the identical /etc/auto.home files.
If only used locally, the NFS is some overhead: the server1 is the local host. In Solaris the automounter detects that and automatically uses an efficient bind mount (in Solaris implemented as another mount type: lofs).
I tell you this because it is THE traditional enterprise standard. Linux has re-engineered (and other commercial Unix have licenced) NFS, autofs/automounter, NIS. And all have implemented openldap.


All times are GMT -5. The time now is 09:02 AM.