Show Table of Contents
18.2.3. Sharing Mounts
Occasionally, certain system administration tasks require access to the same file system from more than one place in the directory tree (for example, when preparing a chroot environment). This is possible, and Linux allows you to mount the same file system to as many directories as necessary. Additionally, the
mount command implements the --bind option that provides a means for duplicating certain mounts. Its usage is as follows:
mount--bindold_directory new_directory
Although this command allows a user to access the file system from both places, it does not apply on the file systems that are mounted within the original directory. To include these mounts as well, type:
mount--rbindold_directory new_directory
Additionally, to provide as much flexibility as possible, Red Hat Enterprise Linux 6 implements the functionality known as shared subtrees. This feature allows the use of the following four mount types:
- Shared Mount
- A shared mount allows the creation of an exact replica of a given mount point. When a mount point is marked as a shared mount, any mount within the original mount point is reflected in it, and vice versa. To change the type of a mount point to a shared mount, type the following at a shell prompt:
mount--make-sharedmount_pointAlternatively, to change the mount type for the selected mount point and all mount points under it, type:mount--make-rsharedmount_pointSee Example 18.4, “Creating a Shared Mount Point” for an example usage. - Slave Mount
- A slave mount allows the creation of a limited duplicate of a given mount point. When a mount point is marked as a slave mount, any mount within the original mount point is reflected in it, but no mount within a slave mount is reflected in its original. To change the type of a mount point to a slave mount, type the following at a shell prompt:
mount--make-slavemount_pointAlternatively, it is possible to change the mount type for the selected mount point and all mount points under it by typing:mount--make-rslavemount_pointSee Example 18.5, “Creating a Slave Mount Point” for an example usage.Example 18.5. Creating a Slave Mount Point
This example shows how to get the content of the/mediadirectory to appear in/mntas well, but without any mounts in the/mntdirectory to be reflected in/media. Asroot, first mark the/mediadirectory as “shared”:~]#
mount --bind /media /media~]#mount --make-shared /mediaThen create its duplicate in/mnt, but mark it as “slave”:~]#
mount --bind /media /mnt~]#mount --make-slave /mntNow verify that a mount within/mediaalso appears in/mnt. For example, if the CD-ROM drive contains non-empty media and the/media/cdrom/directory exists, run the following commands:~]#
mount /dev/cdrom /media/cdrom~]#ls /media/cdromEFI GPL isolinux LiveOS ~]#ls /mnt/cdromEFI GPL isolinux LiveOSAlso verify that file systems mounted in the/mntdirectory are not reflected in/media. For instance, if a non-empty USB flash drive that uses the/dev/sdc1device is plugged in and the/mnt/flashdisk/directory is present, type:~]#
mount /dev/sdc1 /mnt/flashdisk~]#ls /media/flashdisk~]#ls /mnt/flashdisken-US publican.cfg - Private Mount
- A private mount is the default type of mount, and unlike a shared or slave mount, it does not receive or forward any propagation events. To explicitly mark a mount point as a private mount, type the following at a shell prompt:
mount--make-privatemount_pointAlternatively, it is possible to change the mount type for the selected mount point and all mount points under it:mount--make-rprivatemount_pointSee Example 18.6, “Creating a Private Mount Point” for an example usage.Example 18.6. Creating a Private Mount Point
Taking into account the scenario in Example 18.4, “Creating a Shared Mount Point”, assume that a shared mount point has been previously created by using the following commands asroot:~]#
mount --bind /media /media~]#mount --make-shared /media~]#mount --bind /media /mntTo mark the/mntdirectory as “private”, type:~]#
mount --make-private /mntIt is now possible to verify that none of the mounts within/mediaappears in/mnt. For example, if the CD-ROM drives contains non-empty media and the/media/cdrom/directory exists, run the following commands:~]#
mount /dev/cdrom /media/cdrom~]#ls /media/cdromEFI GPL isolinux LiveOS ~]#ls /mnt/cdrom~]#It is also possible to verify that file systems mounted in the/mntdirectory are not reflected in/media. For instance, if a non-empty USB flash drive that uses the/dev/sdc1device is plugged in and the/mnt/flashdisk/directory is present, type:~]#
mount /dev/sdc1 /mnt/flashdisk~]#ls /media/flashdisk~]#ls /mnt/flashdisken-US publican.cfg - Unbindable Mount
- In order to prevent a given mount point from being duplicated whatsoever, an unbindable mount is used. To change the type of a mount point to an unbindable mount, type the following at a shell prompt:
mount--make-unbindablemount_pointAlternatively, it is possible to change the mount type for the selected mount point and all mount points under it:mount--make-runbindablemount_pointSee Example 18.7, “Creating an Unbindable Mount Point” for an example usage.Example 18.7. Creating an Unbindable Mount Point
To prevent the/mediadirectory from being shared, asroot, type the following at a shell prompt:~]#
mount --bind /media /media~]#mount --make-unbindable /mediaThis way, any subsequent attempt to make a duplicate of this mount will fail with an error:~]#
mount --bind /media /mntmount: wrong fs type, bad option, bad superblock on /media, missing codepage or helper program, or other error In some cases useful info is found in syslog - try dmesg | tail or so

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.