Linux mount: Bind or Remount Part Of File Hierarchy At Another Directory

How do I mount the contents of /home/multimedia in two places under Linux operating systems?

If you are using Linux kernel v2.4.0+, you can remount part of the file hierarchy somewhere else using the following mount command syntax. This is useful for NFS servers in /exports. You must type the following commands as the root user. The syntax is

ADVERTISEMENTS

mount --bind /path/to/olddir /path/to/newdir
mount -B olddir newdir

The syntax for /etc/fstab entry is:

/olddir /newdir none bind

In this example, mount /home/multimedia/mp3 and /home/multimedia/videos as follows:
# mkdir -p /exports/{music,videos}
# mount --bind /home/multimedia/mp3 /exports/music
# mount --bind /home/multimedia/videos /exports/videos

Verify new settings:
# mount
# df -a
# mount | egrep -i --color 'music|videos'

Update /etc/fstabe file as follows:
# vi /etc/fstab
Append the following:

/home/multimedia/mp3 /exports/music none bind
/home/multimedia/videos /exports/videos

Save and close the file.

See also:
  • man page mount(8) command.
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
3 comments… add one
  • oOo.Manu.oOo May 14, 2014 @ 23:02

    Thanks ! Very useful for restricted chrooted account too.

    I’ve set up an sftp chrooted account and wanted to share a sub-directory from outside of the root :)

    Wonderful now.

  • oOo.Manu.oOo May 14, 2014 @ 23:04

    You can also add this :

    # mount –bind /mnt/sourcedir targetdir
    # mount -o remount,ro targetdir

    To have a read-only access :)

    • Kamrul Aug 17, 2015 @ 11:27

      Thanks :)

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.