113

Is there a command to mount a folder from one partition to my main partition?

Example of what I'd like to do, which obviously doesn't work:

mount /media/tc1/folder /home/dvad/home

If not by using a command, is there another way I can do this?

Marc.2377
  • 407
user100541
  • 1,233

2 Answers2

193

Yes but before I go that far, couldn't you just symlink?

ln -s /media/tc1/folder ~/home

This link is just a file that is interpreted. It is automatically permanent (until you delete the file).

Failing that you can use mount as you described but the syntax is slightly different:

mount --bind /media/tc1/folder /home/dvad/home

This is not permanent at all, and will be nuked by a restart. If you want it to persist, you'll need something in your /etc/fstab like this:

/media/tc1/folder    /home/dvad/home    none    bind

If you're trying a mount and it's not working, you should make sure that the block-level device is mounted. You can't directly mount a subdirectory of a partition without first mounting the partition.

Oli
  • 293,335
  • 3
    Thanks for the fstab trick. I use mount --bind to "link" folders into a users home folder that I expose to my friends (symlink doesn't play well with chroot) and now I don't have to re-do it or run a script that does it after each reboot. Not sure why I didn't think of using fstab before as I use it for all my media drives. Thanks again! – JoshStrange Oct 31 '14 at 15:31
  • 4
    mount --bind source destination – Michel Samia Nov 27 '14 at 14:03
  • 7
    mount --bind is useful in chroot'ed environment - since symlinks doesn't work there. – abyss.7 Nov 20 '15 at 10:46
  • I'm trying a mount and it's not working, and I made sure the partition is mounted. What might be going on? – Marc.2377 Jul 03 '16 at 11:08
  • @Marc.2377 Ensure the folder you want to mount to exists and that you have chmod'd that folder. – SilentSteel Sep 25 '16 at 06:57
  • Just adding a note- this is a good alternative to the more complex Apache directory ALIAS and often solves Forbidden issues in a safer way. Thanks! – SilentSteel Sep 25 '16 at 07:00
  • Shouldn't the fstab entry be /media/tc1/folder /home/dvad/home none bind 0 0 instead? Isn't the 0 0 at the end required? – Gabriel Staples Apr 06 '17 at 22:17
  • 1
    @GabrielStaples Nope. man fstab will tell you the final two fields Defaults to zero (don't {dump,fsck}) if not present. – Oli Apr 07 '17 at 08:59
  • Symlinks also don't work in webdav, where mount --bind does. – Sridhar Sarnobat Mar 10 '18 at 05:57
  • I wanted another user to have access to a folder inside my partition but not the partition itself. So I mounted that folder inside /media/<another user name>/folder using mount --bind. I guess you can't do this with symlink (I didn't try). – Mohit Atray Aug 24 '21 at 11:39
  • This is very good use also for snap as I have homedir elsewhere than /home/user – Antti Rytsölä Mar 15 '24 at 09:58
18

An alternative to mount:

bindfs --no-allow-other /media/tc1/folder /home/dvad/home

May require sudo apt install bindfs.

Like with mount, this will be a (non-permanent) actual mount point. That means for instance version-control systems will not track it as a mere symbolic reference, but see the files “in there” as if they were lying on the single partition. Meanwhile, like for ln -s, you do not need superuser permissions for bindfs as you would for mount.

Unmount with fusermount -u /home/dvad/home (or by restarting).