• Aucun résultat trouvé

Note: Determining the UUID and Label of a Particular Device

18.2.3. Sharing Mount s

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 mo unt command implements the --bi nd option that provides a means for duplicating certain mounts. Its usage is as follows:

mo unt --bi nd old_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:

mo unt --rbi nd old_directory new_directory

Additionally, to provide as much flexibility as possible, Red Hat Enterprise Linux 7 implements the functionality known as shared subtrees. This feature allows the use of the following four mount types:

Sh ared Mo u n t

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:

mo unt --make-shared mount_point

Alternatively, to change the mount type for the selected mount point and all mount points under it, type:

mo unt --make-rshared mount_point

See Example 18.4, “ Creating a Shared Mount Point” for an example usage.

Examp le 18.4 . Creat in g a Sh ared Mo u n t Po in t

There are two places where other file systems are commonly mounted: the /med i a directory for removable media, and the /mnt directory for temporarily mounted file systems. By using a shared mount, you can make these two directories share the same content. To do so, as ro o t, mark the /med i a directory as “ shared” :

~]# mo unt --bi nd /med i a /med i a

~]# mo unt --make-shared /med i a

Then create its duplicate in /mnt by using the following command:

⁠Chapt er 1 8 . Using t he mount Command

It is now possible to verify that a mount within /med i a also appears in /mnt. For example, if the CD-ROM drive contains non-empty media and the /med i a/cd ro m/

directory exists, run the following commands:

~]# mo unt /d ev/cd ro m /med i a/cd ro m

~]# l s /med i a/cd ro m

EFI GPL isolinux LiveOS

~]# l s /mnt/cd ro m

EFI GPL isolinux LiveOS

Similarly, it is possible to verify that any file system mounted in the /mnt directory is reflected in /med i a. For instance, if a non-empty USB flash drive that uses the

/d ev/sd c1 device is plugged in and the /mnt/fl ashd i sk/ directory is present, type:

~]# mo unt /d ev/sd c1 /mnt/fl ashd i sk

~]# l s /med i a/fl ashd i sk en-US publican.cfg

~]# l s /mnt/fl ashd i sk en-US publican.cfg Slave Mo u n t

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:

mo unt --make-sl ave mount_point

Alternatively, it is possible to change the mount type for the selected mount point and all mount points under it by typing:

mo unt --make-rsl ave mount_point

See Example 18.5, “ Creating a Slave Mount Point” for an example usage.

Examp le 18.5. Creat in g a Slave Mo u n t Po in t

This example shows how to get the content of the /med i a directory to appear in /mnt as well, but without any mounts in the /mnt directory to be reflected in /med i a. As ro o t, first mark the /med i a directory as “ shared” :

~]# mo unt --bi nd /med i a /med i a

~]# mo unt --make-shared /med i a

Then create its duplicate in /mnt, but mark it as “ slave” :

~]# mo unt --bi nd /med i a /mnt

~]# mo unt --make-sl ave /mnt

Now verify that a mount within /med i a also appears in /mnt. For example, if the CD-ROM drive contains non-empty media and the /med i a/cd ro m/ directory exists, run the following commands:

~]# mo unt /d ev/cd ro m /med i a/cd ro m

~]# l s /med i a/cd ro m

EFI GPL isolinux LiveOS

~]# l s /mnt/cd ro m

EFI GPL isolinux LiveOS

Also verify that file systems mounted in the /mnt directory are not reflected in /med i a. For instance, if a non-empty USB flash drive that uses the /d ev/sd c1 device is plugged in and the /mnt/fl ashd i sk/ directory is present, type:

~]# mo unt /d ev/sd c1 /mnt/fl ashd i sk

~]# l s /med i a/fl ashd i sk

~]# l s /mnt/fl ashd i sk en-US publican.cfg Privat e Mo u n t

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:

mo unt --make-pri vate mount_point

Alternatively, it is possible to change the mount type for the selected mount point and all mount points under it:

mo unt --make-rpri vate mount_point

See Example 18.6, “ Creating a Private Mount Point” for an example usage.

Examp le 18.6 . Creat in g a Privat e Mo u n t Po in t

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 as ro o t:

~]# mo unt --bi nd /med i a /med i a

~]# mo unt --make-shared /med i a

~]# mo unt --bi nd /med i a /mnt To mark the /mnt directory as “ private” , type:

~]# mo unt --make-pri vate /mnt

It is now possible to verify that none of the mounts within /med i a appears in /mnt. For example, if the CD-ROM drives contains non-empty media and the /med i a/cd ro m/

directory exists, run the following commands:

~]# mo unt /d ev/cd ro m /med i a/cd ro m

~]# l s /med i a/cd ro m

EFI GPL isolinux LiveOS

⁠Chapt er 1 8 . Using t he mount Command

It is also possible to verify that file systems mounted in the /mnt directory are not reflected in /med i a. For instance, if a non-empty USB flash drive that uses the

/d ev/sd c1 device is plugged in and the /mnt/fl ashd i sk/ directory is present, type:

~]# mo unt /d ev/sd c1 /mnt/fl ashd i sk

~]# l s /med i a/fl ashd i sk

~]# l s /mnt/fl ashd i sk en-US publican.cfg Un b in d ab le Mo u n t

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:

mo unt --make-unbi nd abl e mount_point

Alternatively, it is possible to change the mount type for the selected mount point and all mount points under it:

mo unt --make-runbi nd abl e mount_point

See Example 18.7, “ Creating an Unbindable Mount Point” for an example usage.

Examp le 18.7. Creat in g an Un b in d ab le Mo u n t Po in t

To prevent the /med i a directory from being shared, as ro o t, type the following at a shell prompt:

~]# mo unt --bi nd /med i a /med i a

~]# mo unt --make-unbi nd abl e /med i a

This way, any subsequent attempt to make a duplicate of this mount will fail with an error:

~]# mo unt --bi nd /med i a /mnt

mount: 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

18.2.4 . Moving a Mount Point

To change the directory in which a file system is mounted, use the following command:

mo unt --mo ve old_directory new_directory

See Example 18.8, “ Moving an Existing NFS Mount Point” for an example usage.

Examp le 18.8. Mo vin g an Exist in g NFS Mo u n t Po in t

An NFS storage contains user directories and is already mounted in /mnt/userd i rs/. As ro o t, move this mount point to /ho me by using the following command:

~]# mo unt --mo ve /mnt/userd i rs /ho me

To verify the mount point has been moved, list the content of both directories:

~]# l s /mnt/userd i rs

~]# l s /ho me jill joe