move /home to a directory on a partition that is not mounted as /home

Issues related to applications and software problems
Posts: 33
Joined: 2011/03/22 17:32:25
Location: Boston

Re: move /home to a directory on a partition that is not mounted as /home

Post by LMHmedchem » 2020/02/18 23:34:52

jlehtone wrote:
2020/02/18 20:21:34
Didn't linux_data have 'user_home'?

Code: Select all

/mnt/linux_data/user_home  /home  none  bind  0 0
It appears that I was just stupid and wrote the bind rule backwards. I entered,

Code: Select all

/home  /mnt/linux_data/user_home    none  bind  0 0
instead of,

Code: Select all

/mnt/linux_data/user_home  /home  none  bind  0 0
The second version here works. It was not necessary to add any additional options along with bind.

I have it working, but there are still a few caveats to getting it right.

Your /home partition also contains the directory for your username,

Code: Select all

where your profile information is stored in /user_name. When I made the rule,

Code: Select all

/mnt/linux_data/user_name  /home  none  bind  0 0
there was no /user_name directory inside (under) /mnt/linux_data/user_name. The OS created a new /user_name directory so I ended up with a blank profile in /mnt/linux_data/user_name/user_name. None of my profile information was carried over.

It is actually necessary to make the mount rule,

Code: Select all

/mnt/linux_data  /home  none  bind  0 0
without the /user_name level, but it is necessary for /mnt/linux_data/user_name to exist and contain your profile information.

This results in /mnt/linux_data being mounted as /home and then the path /home/user_name will be valid.

I created the directory and copied the data from the original /home location like,

Code: Select all

sudo mkdir /mnt/linux_data/user_name
sudo cp -rfp  /home/*  /mnt/linux_data/user_name
sudo cp -rfp  /home/.  /mnt/linux_data/user_name
I then added the bind rule to fstab and restarted. When I log in to my account, my home directory now points to /mnt/linux_data/user_name and my profile is intact. I can't yet confirm that nothing got broken but everything works as far as I can tell.

Is there anything I should be looking for as to what might not be working with /home now in a different location in the filesystem?


User avatar
Posts: 2931
Joined: 2007/12/11 08:17:33
Location: Finland

Re: move /home to a directory on a partition that is not mounted as /home

Post by jlehtone » 2020/02/19 07:27:27

I can't fathom all the things you have.

Let me tell a hypothetical story to keep my brain simple.

Once upon a time there were three partitions: sda2, sda3, and sdb1. Each had a filesystem. They were mounted:

Code: Select all

sda2 /
sda3 /home
sdb1 /convoluted/location/earth
The paths /home and /convoluted/location/earth were on sda2. Their contents were on sda3 and sdb1.

There was account 'medchem' (and 'jane' and 'john' and ...).
For medchem, $HOME == /home/medchem. The sda2 had directory 'medchem'
(Almost*) all data/profile of medchem was in /home/medchem/

*mailspool and crontab are elsewhere

The sdb3 had directory 'new_hope'. One could see it as /convoluted/location/earth/new_hope

One day before Yule, when nobody was logged in, the root did

Code: Select all

rsync -aHAX --delete /home/medchem/ /convoluted/location/earth/new_hope/medchem/
# same for other accounts
umount /home
umount /convoluted/location/earth
mkdir /mnt/somename
mount /dev/sdb1 /mnt/somename
mount --bind /mnt/somename/new_hope /home
Now sdb1/new_hope/medchem is a copy of sda3/medchem and seen as /home/medchem.
(Then there were the fstab to update before next reboot ...)

Posts: 113
Joined: 2020/01/17 09:01:44

Re: move /home to a directory on a partition that is not mounted as /home

Post by sml » 2020/02/19 10:08:55

Here is my setup. I don't use bind mounts. A few local users have their home directories under /localhome.

Code: Select all

$ grep home /etc/fstab
/dev/mapper/centos7-home /localhome xfs logdev=/dev/mapper/centos7-hlog 0 0
Home directories for all the others get automounted from an NFS server through autofs under /home.

IIRC, after moving local users to /localhome, I did

Code: Select all

semanage fcontext -a -e /home /localhome
Not quite sure about genhomedircon, but I guess I never invoked it directly. HTH.

Post Reply

Return to “CentOS 7 - Software Support”