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

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

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

Post by LMHmedchem » 2020/02/17 17:03:41

Hello,

I am looking to move my /home directory to a different location that is not its own partition like it is now. Currently, /home is on the same physical drive as / and I would like to move it. The drive I have in mind is a shared data drive. The shared drive is currently mounted by uuid as,

Code: Select all

/run/media/user_name/linux_data/
This drive has some directories at the top level that I don't want to be under /home. Currently there are,

Code: Select all

/run/media/user_name/linux_data/application_data/
/run/media/user_name/linux_data/configuration/
I would like to add,

Code: Select all

/run/media/user_name/linux_data/user_home/
where user_home becomes the /home directory.

I am not exactly sure how to do this. The partition is already mounted. I could mount the entire partition as /home, but I don't want everything on the partition in /home.

Can I just do a bind in /etc/fstab

Code: Select all

# /etc/fstab
/home   /home/run/media/user_name/linux_data/user_home   none   bind   0   0
LMHmedchem
Last edited by LMHmedchem on 2020/02/17 18:25:34, edited 2 times in total.

tunk
Posts: 725
Joined: 2017/02/22 15:08:17

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

Post by tunk » 2020/02/17 17:48:52

I don't know if this is recommended: move and then delete everything
in /home and make it a symbolic link to the new location.

Edit: Or you could rename /home to e.g. /home-old, and then create the link.

LMHmedchem
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/17 18:11:35

Since the shared partition is already mounted by uuid,

Code: Select all

# shared linux data partition
UUID=a89334f7-59b7-4d04-b89b-a5a30c379644  /run/media/user_name/linux_data  ext4  defaults  1 2
I thought I could just add,

Code: Select all

# shared linux data partition
/run/media/user_name/linux_data/user_home  /home  ext4  defaults  1 2
but this looks like it is mounting an ext4 file system within an existing mounted ext4 file system. This is why I think I need bind or something similar. I think you can also change the location of /home in the user settings.

Surly there must be a standard way of doing this but I haven't run across it yet. The default /home directory is just part of the / partition, so there must be a way to make it part of the /whatever partition. I don't think that the default fstab has a /home entry (when /home hasn't been deliberately specified as somewhere other than under /). It's probably obvious and I'm just being thick today.

LMHmedchem

User avatar
jlehtone
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/17 19:03:23

LMHmedchem wrote:
2020/02/17 18:11:35
This is why I think I need bind or something similar. I think you can also change the location of /home in the user settings.
You mean something like:

Code: Select all

/run/media/user_name/linux_data/user_home  /home  none  bind  0 0
PS. Output of 'findmnt' is interesting.

LMHmedchem
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/17 19:32:41

jlehtone wrote:
2020/02/17 19:03:23
You mean something like:

Code: Select all

/run/media/user_name/linux_data/user_home  /home  none  bind  0 0
That is what I suggested adding to fstab in the initial post but I don't know if it would work.

I think that you could also do something like the following,

Code: Select all

usermod --home /run/media/user_name/linux_data/user_home --move-home user_name
I am not sure if either of these options would work or if there are potential problems.
jlehtone wrote:
2020/02/17 19:03:23
PS. Output of 'findmnt' is interesting.
This is a nice collection of information about the filesystem but I don't see how it helps with this. Am I missing something???

LMHmedchem

User avatar
jlehtone
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/17 21:30:16

I do use bind mounts. Also for /home.

You obviously cannot move what is in use. Therefore, you cannot be logged in as anyone, whose home is about to move.
I would use 'rsync' to copy. Erase source, once copy is complete. Then bind mount. Verify selinux labels.

Yes, rather than mounting new /home you can "move users" with usermod. However, that is, IMHO, a long path for HOME.

The findmnt does not help here. The way it shows those bind mounts ...


Overall, the /run/media/user_name/linux_data looks unexpected location to me.
RHEL 7 wrote:... the /run directory is a temporary file storage system (tmpfs) that bind mounts the /var/run directory.
or
/var/run is a symbolic link to /run

LMHmedchem
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/17 22:25:14

jlehtone wrote:
2020/02/17 21:30:16
I do use bind mounts. Also for /home.

You obviously cannot move what is in use. Therefore, you cannot be logged in as anyone, whose home is about to move.
I would just edit the fstab file for the bind mount and restart. I don't think the fstab file is used for anything except at boot time.
jlehtone wrote:
2020/02/17 21:30:16
I would use 'rsync' to copy. Erase source, once copy is complete. Then bind mount. Verify selinux labels.
I already have a copy of the data in /home. Since /home is its own partition already, I just have to comment out the fstab that is mounting it. After I have it working, I will delete the partition and recover the disk space. How do I go about checking if there are any issues with selinux? Will I need to relabel?
jlehtone wrote:
2020/02/17 21:30:16
Overall, the /run/media/user_name/linux_data looks unexpected location to me.
When I mounted this (and other) partitions in dolphin by clicking on the device in the devices list and entering the root password the mounted filesystem landed in /run/media/user_name/. I assumed that there was some good reason for the OS mounting the partitions in this location so I copied those locations into the fstab entries I made to auto mount on boot.

I think that in opensuse I just have them in /mnt. I could certainly change the mount location if you think it makes more sense to have them elsewhere.

I could change to,

Code: Select all

# shared linux data partition
UUID=a89334f7-59b7-4d04-b89b-a5a30c379644  /mnt/linux_data  ext4  defaults  1 2
I see in many examples that partitions are just mounted somewhere like /linux_data instead of inside some existing system directory under /. What is considered best practice here?

LMHmedchem

User avatar
jlehtone
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/18 07:13:54

Sorry, missed the "/home is its own partition already". Yes, the "move" will be a simple "umount /home ; update fstab ; mount /home" (after the copy).

'restorecon' can (re)apply default labels to /home. (If you would usermod move-home, then you should set the label of the new homes first.)


I just like to keep "explicit" (fstab, autofs) mounts clearly separate (I do use /mnt too for "volumes" and bind-mount to other places) from the place, where Desktop/whatever (auto)mounts "temporary external" (e.g. flash). Somehow, "every user's" data feel better in "common" mount-point, rather than under "run..username". Particularly, if the GUI (which I don't use) has "Eject" buttons.

LMHmedchem
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 17:07:40

I changed fstab to mount the additional partitions in /mnt. This includes the partition with the directory that I would like to be /home. I also added the bind mount for /home.

Code: Select all

# shared linux data partition, /home is here by a bind mount
UUID=a89334f7-59b7-4d04-b89b-a5a30c379644  /mnt/linux_data  ext4  defaults  1 0

# bind mount /home to directory /user_name in /linux_data
/home   /mnt/linux_data/user_name   none   bind   0 0
I am now getting a "Call to lnusertemp failed (temporary directories full?)" error on after the login screen. I enter my username and password and then the error message dialog appears. I have also tried to changing the login to gnome and a kde plasma fail-safe session but that doesn't help either.

I think it is likely that somehow the OS cannot use the home directory I set up with the bind. I don't know if that is a permissions issue or something else.

The partition that the home directory is bound to is mounted with the default mount options. Do I need to change those options?

According to the mount man page, the defaults are,

Code: Select all

rw = mount the filesystem as read-write
suid = allow the operation of suid, and sgid bits
dev = interpret character or block special devices on the filesystem
exec = allow the execution binaries that are on that partition
auto = file system will mount automatically at boot
nouser = only allow root to mount the filesystem
async = I/O should be done asynchronously
Is there a problem with the way I wrote the bind rule? It looks like "bind" is the only option I used for the bind rule. I have also tried,

Code: Select all

# bind mount /home to directory /user_name in /linux_data
/home   /mnt/linux_data/user_name   none   defaults,bind   0 0
but that doesn't fix the issue.


LMHmedchem

User avatar
jlehtone
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/18 20:21:34

Code: Select all

man fstab
what where fstype options

what: This field describes the block special device or remote filesystem to be mounted. Block special device node, <host>:<dir>, UUID, LABEL, ...

where: This field describes the mount point for the filesystem. For swap partitions, this field should be specified as `none'.

You mount the (empty, on / filesystem) /home to /mnt/linux_data/user_name (hiding whatever /mnt/linux_data/user_name has)

Didn't linux_data have 'user_home'?

Code: Select all

/mnt/linux_data/user_home  /home  none  bind  0 0

Post Reply

Return to “CentOS 7 - Software Support”