How do I permanently mount a separate partition as folder in a separate home partition?

2,533

Solution 1

TL,DR: I recommend symlinks.

If you mount a partition to a mount point that isn't in the root partition, you must take care to mount the host partition first and unmount the host partition first. For example, if you have separate partitions for /, /home and /home/htorque/Documents, then you must mount /home before /home/htorque/Documents. If you list the partitions in /etc/fstab, then it's enough to list /home before /home/htorque/Documents, since the entries are mounted in order at boot time. Thus nested mount points are not a problem in normal operation.

Nested mount points can be a problem in unusual circumstances. Suppose the disk containing one of the partition crashes, or you're doing maintenance such as unmounting a filesystem to move it to a different disk. You cannot unmount /home unless you've unmounted the partitions whose mount point is on it. If /home is not mounted at boot time because its filesystem is damaged, then /home/htorque/Documents will not be mounted either. Should you decide to rename /home/torque/Documents, you'll need to unmount the partition first. Furthermore, if at any point /home/htorque/Documents is not mounted and you accidentally drop a file in that directory, then the file will mysteriously vanish when you then mount /home/htorque/Documents.

One case where you will not be able to (conveniently) use mount points under your home directory is if it is encrypted and mounted when you log in, for example the way Ubuntu uses ecryptfs if you ask for your home directory to be encrypted. You would have to mount the other partitions manually (or from a login script) afterwards, and to be careful to unmount them before logging out.

A limitation which may or may not be relevant is that if you want your home directory not to be publicly readable but you do want e.g. your music to be publicly readable, then the path to your music directory must not go through your home directory. This is another argument against mount points under your home directory in a specific cirsumstance.

Bind mounts won't buy you much here. They're useful when a symbolic link won't do, for example when you need files to be available in a chroot. But they combine the heavy maintenance of mount points with some of the downsides of symbolic links (the files also exist elsewhere) plus downsides of their own (multiple canonical paths to a file require special care when doing backups, among other things).

So I recommend to create partitions mounted directly on the root partition (not necessarily directly underneath the root directory), and to create symbolic links. Or you can configure different path for those directories in ~/.config/user-dirs.dirs.

Solution 2

Symlinks are much easier than other approaches, but I wouldn't call them a "clean" approach - If you delete a symlink, for example, you only delete the link, not the file it points to, resulting in what looks like inconsistent behavior. You can use for example bind mounts:

mount --bind /media/my-disk /home/user/Documents

Those are generally indistinguishable from the real thing.

Solution 3

Symbolic links for the subdirs of home is by far the cleanest approach.

While I think you could use a filesystem overlay, it'll be a lot more complex to initialize the directories when you create a new user - you'd need to create new branches for each directory or use pseudo links (which are effectively little different from symbolic links).

Share:
2,533

Related videos on Youtube

MH.
Author by

MH.

Updated on September 18, 2022

Comments

  • MH.
    MH. over 1 year

    I have created a Maven2 project. Everything works fine. Now, I have set up a Hudson project in order to make nightly builds possible. Hudson should check out the current project state from a Subversion repository, run the tests, build the project and deploy everyting to a repository. My Subversion repositroy contains my Maven2 project but no jars located in my local Maven repository (.m2). That's probably why hudson finishes with a failure, saying that some 3rd party jars are't available. Here, I have to say that there are some jars in my local Maven repository (.m2), which aren't available in any Maven repositories. Hence, there is no possibility to download these jars. Has Hudson the ability to connect to the local .m2 repository? Or is there another way to make these jar files available to Hudson?

    Thanks a million in advance for your help.

    • Admin
      Admin over 12 years
      Yes, you have to mount in order, I just tested and it hid the existing directory when I mounted something to its containing directory.
    • Admin
      Admin over 12 years
      Its time you consider automounter (or autofs) for better options. Wherein, given for user requirements, you can have seperate user specific partitions on a share/partitions like user1_Documents, user1_Videos, user1_Music and have them mounted under /home/user1/{Documents,Videos,Music} respectively. It can get difficult when you have many partitions to manage otherwise though..
  • Marcio Rinaldi
    Marcio Rinaldi over 12 years
    While I wouldn't consider any of the unusual circumstances you mention a real problem in my case, in my opinion this answer explains best what you have to think about when taking that route. Given that my underlying goal is to reduce complexity of my partition chaos, I think the three answers have changed my mind. ;)
  • Geppettvs D'Constanzo
    Geppettvs D'Constanzo almost 6 years
    This is doing the trick for sharing a folder between a dual boot Win/Linux system in which I share a folder from Windows to Linux. Thank you.