2.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). To address such requirements, the
mount
command implements the --bind
option that provides a means for duplicating certain mounts. Its usage is as follows:
mount --bind old_directory new_directory
mount --bind old_directory new_directory
Although the above 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 --rbind old_directory new_directory
mount --rbind old_directory new_directory
Additionally, to provide as much flexibility as possible, Red Hat Enterprise Linux 5.10 implements the functionality known as shared subtrees. This feature allows you to use the following four mount types:
- Shared Mount
- A shared mount allows you to create an exact replica of a given mount point. When a shared mount is created, any mount within the original mount point is reflected in it, and vice versa. To create a shared mount, type the following at a shell prompt:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow mount --make-shared mount_point
mount --make-shared mount_point
Alternatively, you can change the mount type for the selected mount point and all mount points under it:Copy to Clipboard Copied! Toggle word wrap Toggle overflow mount --make-rshared mount_point
mount --make-rshared mount_point
See Example 2.4, “Creating a Shared Mount Point” for an example usage. - Slave Mount
- A slave mount allows you to create a limited duplicate of a given mount point. When a slave mount is created, any mount within the original mount point is reflected in it, but no mount within a slave mount is reflected in its original. To create a slave mount, type the following at a shell prompt:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow mount --make-slave mount_point
mount --make-slave mount_point
Alternatively, you can change the mount type for the selected mount point and all mount points under it:Copy to Clipboard Copied! Toggle word wrap Toggle overflow mount --make-rslave mount_point
mount --make-rslave mount_point
See Example 2.5, “Creating a Slave Mount Point” for an example usage.Example 2.5. Creating a Slave Mount Point
Imagine you want the content of the/media
directory to appear in/mnt
as well, but you do not want any mounts in the/mnt
directory to be reflected in/media
. To do so, asroot
, first mark the/media
directory as “shared”:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# mount --bind /media /media ~]# mount --make-shared /media
~]# mount --bind /media /media ~]# mount --make-shared /media
Then create its duplicate in/mnt
, but mark it as “slave”:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# mount --bind /media /mnt ~]# mount --make-slave /mnt
~]# mount --bind /media /mnt ~]# mount --make-slave /mnt
You can now verify that a mount within/media
also appears in/mnt
. For example, if you have non-empty media in your CD-ROM drive and the/media/cdrom/
directory exists, run the following commands:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# mount /dev/cdrom /media/cdrom ~]# ls /media/cdrom EFI GPL isolinux LiveOS ~]# ls /mnt/cdrom EFI GPL isolinux LiveOS
~]# mount /dev/cdrom /media/cdrom ~]# ls /media/cdrom EFI GPL isolinux LiveOS ~]# ls /mnt/cdrom EFI GPL isolinux LiveOS
You can also verify that file systems mounted in the/mnt
directory are not reflected in/media
. For instance, if you have a non-empty USB flash drive that uses the/dev/sdc1
device plugged in and the/mnt/flashdisk/
directory is present, type: :Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# mount /dev/sdc1 /mnt/flashdisk ~]# ls /media/flashdisk ~]# ls /mnt/flashdisk en-US publican.cfg
~]# mount /dev/sdc1 /mnt/flashdisk ~]# ls /media/flashdisk ~]# ls /mnt/flashdisk en-US publican.cfg
- Private Mount
- A private mount allows you to create an ordinary mount. When a private mount is created, no subsequent mounts within the original mount point are reflected in it, and no mount within a private mount is reflected in its original. To create a private mount, type the following at a shell prompt:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow mount --make-private mount_point
mount --make-private mount_point
Alternatively, you can change the mount type for the selected mount point and all mount points under it:Copy to Clipboard Copied! Toggle word wrap Toggle overflow mount --make-rprivate mount_point
mount --make-rprivate mount_point
See Example 2.6, “Creating a Private Mount Point” for an example usage.Example 2.6. Creating a Private Mount Point
Taking into account the scenario in Example 2.4, “Creating a Shared Mount Point”, assume that you have previously created a shared mount point by using the following commands asroot
:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# mount --bind /media /media ~]# mount --make-shared /media ~]# mount --bind /media /mnt
~]# mount --bind /media /media ~]# mount --make-shared /media ~]# mount --bind /media /mnt
To mark the/mnt
directory as “private”, type:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# mount --make-private /mnt
~]# mount --make-private /mnt
You can now verify that none of the mounts within/media
appears in/mnt
. For example, if you have non-empty media in your CD-ROM drive and the/media/cdrom/
directory exists, run the following commands:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# mount /dev/cdrom /media/cdrom ~]# ls /media/cdrom EFI GPL isolinux LiveOS ~]# ls /mnt/cdrom ~]#
~]# mount /dev/cdrom /media/cdrom ~]# ls /media/cdrom EFI GPL isolinux LiveOS ~]# ls /mnt/cdrom ~]#
You can also verify that file systems mounted in the/mnt
directory are not reflected in/media
. For instance, if you have a non-empty USB flash drive that uses the/dev/sdc1
device plugged in and the/mnt/flashdisk/
directory is present, type:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# mount /dev/sdc1 /mnt/flashdisk ~]# ls /media/flashdisk ~]# ls /mnt/flashdisk en-US publican.cfg
~]# mount /dev/sdc1 /mnt/flashdisk ~]# ls /media/flashdisk ~]# ls /mnt/flashdisk en-US publican.cfg
- Unbindable Mount
- An unbindable mount allows you to prevent a given mount point from being duplicated whatsoever. To create an unbindable mount, type the following at a shell prompt:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow mount --make-unbindable mount_point
mount --make-unbindable mount_point
Alternatively, you can change the mount type for the selected mount point and all mount points under it:Copy to Clipboard Copied! Toggle word wrap Toggle overflow mount --make-runbindable mount_point
mount --make-runbindable mount_point
See Example 2.7, “Creating an Unbindable Mount Point” for an example usage.Example 2.7. Creating an Unbindable Mount Point
To prevent the/media
directory from being shared, asroot
, type the following at a shell prompt:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# mount --bind /media /media ~]# mount --make-unbindable /media
~]# mount --bind /media /media ~]# mount --make-unbindable /media
This way, any subsequent attempt to make a duplicate of this mount will fail with an error:Copy to Clipboard Copied! Toggle word wrap Toggle overflow ~]# mount --bind /media /mnt mount: wrong fs type, bad option, bad superblock on /media/, missing code page or other error In some cases useful info is found in syslog - try dmesg | tail or so
~]# mount --bind /media /mnt mount: wrong fs type, bad option, bad superblock on /media/, missing code page or other error In some cases useful info is found in syslog - try dmesg | tail or so