Linux does not prevent a user from mounting a file system to a directory with a file system already attached to it. To determine whether a particular directory serves as a mount point, run the # blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3" 9 utility with the directory as its argument and verify the exit code:
findmnt directory; echo $?If no file system is attached to the directory, the given command returns $ mount -t type device directory0.
When you run the # blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3" 5 command without all required information, that is without the device name, the target directory, or the file system type, the # blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3" 5 reads the contents of the $ mount -t type device directory3 file to check if the given file system is listed. The $ mount -t type device directory3 file contains a list of device names and the directories in which the selected file systems are set to be mounted as well as the file system type and mount options. Therefore, when mounting a file system that is specified in $ mount -t type device directory3, you can choose one of the following options:
mount [option…] directory mount [option…] deviceNote that permissions are required to mount the file systems unless the command is run as $ mount -t type device directory6 (see Section 19.2.2, “Specifying the Mount Options”).
Note
To determine the UUID and—if the device uses it—the label of a particular device, use the $ mount -t type device directory7 command in the following form:
blkid deviceFor example, to display information about # blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3" 6:
# blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3"19.2.1. Specifying the File System Type
In most cases, # blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3" 5 detects the file system automatically. However, there are certain file systems, such as ~]# mount -t vfat /dev/sdc1 /media/flashdisk0 (Network File System) or ~]# mount -t vfat /dev/sdc1 /media/flashdisk1 (Common Internet File System), that are not recognized, and need to be specified manually. To specify the file system type, use the # blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3" 5 command in the following form:
$ mount -t type device directoryTable 19.1, “Common File System Types” provides a list of common file system types that can be used with the # blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3" 5 command. For a complete list of all available file system types, see the section called “Manual Page Documentation”.
Table 19.1. Common File System Types
TypeDescription~]# mount -t vfat /dev/sdc1 /media/flashdisk4The ~]# mount -t vfat /dev/sdc1 /media/flashdisk4 file system.~]# mount -t vfat /dev/sdc1 /media/flashdisk6The ~]# mount -t vfat /dev/sdc1 /media/flashdisk6 file system.~]# mount -t vfat /dev/sdc1 /media/flashdisk8The ~]# mount -t vfat /dev/sdc1 /media/flashdisk8 file system.mount -o options device directory0The mount -o options device directory0 file system.mount -o options device directory2The mount -o options device directory2 file system.mount -o options device directory4The mount -o options device directory5 file system. It is commonly used by optical media, typically CDs.mount -o options device directory6The ~]# mount -t vfat /dev/sdc1 /media/flashdisk0 file system. It is commonly used to access files over the network.mount -o options device directory8The mount -o options device directory9 file system. It is commonly used to access files over the network.# mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom0The # mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom1 file system. It is commonly used by optical media, typically DVDs.# mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom2The # mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom3 file system. It is commonly used on machines that are running the Windows operating system, and on certain digital media such as USB flash drives or floppy disks.
See Example 19.2, “Mounting a USB Flash Drive” for an example usage.
Example 19.2. Mounting a USB Flash Drive
Older USB flash drives often use the FAT file system. Assuming that such drive uses the # mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom4 device and that the # mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom5 directory exists, mount it to this directory by typing the following at a shell prompt as $ mount -t type device directory6:
~]# mount -t vfat /dev/sdc1 /media/flashdisk19.2.2. Specifying the Mount Options
To specify additional mount options, use the command in the following form:
mount -o options device directoryWhen supplying multiple options, do not insert a space after a comma, or # blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3" 5 interprets incorrectly the values following spaces as additional parameters.
Table 19.2, “Common Mount Options” provides a list of common mount options. For a complete list of all available options, consult the relevant manual page as referred to in the section called “Manual Page Documentation”.
Table 19.2. Common Mount Options
OptionDescription# mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom8Allows the asynchronous input/output operations on the file system.# mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom9Allows the file system to be mounted automatically using the $ mount --bind old_directory new_directory0 command.$ mount --bind old_directory new_directory1Provides an alias for $ mount --bind old_directory new_directory2.$ mount --bind old_directory new_directory3Allows the execution of binary files on the particular file system.$ mount --bind old_directory new_directory4Mounts an image as a loop device.$ mount --bind old_directory new_directory5Default behavior disallows the automatic mount of the file system using the $ mount --bind old_directory new_directory0 command.$ mount --bind old_directory new_directory7Disallows the execution of binary files on the particular file system.$ mount --bind old_directory new_directory8Disallows an ordinary user (that is, other than $ mount -t type device directory6) to mount and unmount the file system.findmnt directory; echo $?00Remounts the file system in case it is already mounted.findmnt directory; echo $?01Mounts the file system for reading only.findmnt directory; echo $?02Mounts the file system for both reading and writing.findmnt directory; echo $?03Allows an ordinary user (that is, other than $ mount -t type device directory6) to mount and unmount the file system.
See Example 19.3, “Mounting an ISO Image” for an example usage.
Example 19.3. Mounting an ISO Image
An ISO image (or a disk image in general) can be mounted by using the loop device. Assuming that the ISO image of the Fedora 14 installation disc is present in the current working directory and that the findmnt directory; echo $?05 directory exists, mount the image to this directory by running the following command:
# mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdromNote that ISO 9660 is by design a read-only file system.
19.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 # blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3" 5 command implements the findmnt directory; echo $?07 option that provides a means for duplicating certain mounts. Its usage is as follows:
$ mount --bind old_directory new_directoryAlthough 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, use the following command:
findmnt directory; echo $?0Additionally, 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:
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:
findmnt directory; echo $?1Alternatively, to change the mount type for the selected mount point and all mount points under it:
findmnt directory; echo $?2See Example 19.4, “Creating a Shared Mount Point” for an example usage.
Example 19.4. Creating a Shared Mount Point
There are two places where other file systems are commonly mounted: the findmnt directory; echo $?08 directory for removable media, and the findmnt directory; echo $?09 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 $ mount -t type device directory6, mark the findmnt directory; echo $?08 directory as shared:
findmnt directory; echo $?3Create its duplicate in findmnt directory; echo $?09 by using the following command:
findmnt directory; echo $?4It is now possible to verify that a mount within findmnt directory; echo $?08 also appears in findmnt directory; echo $?09. For example, if the CD-ROM drive contains non-empty media and the findmnt directory; echo $?05 directory exists, run the following commands:
findmnt directory; echo $?5Similarly, it is possible to verify that any file system mounted in the findmnt directory; echo $?09 directory is reflected in findmnt directory; echo $?08. For instance, if a non-empty USB flash drive that uses the # mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom4 device is plugged in and the findmnt directory; echo $?19 directory is present, type:
findmnt directory; echo $?6Slave MountA 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:
findmnt directory; echo $?7Alternatively, it is possible to change the mount type for the selected mount point and all mount points under it by typing:
findmnt directory; echo $?8See Example 19.5, “Creating a Slave Mount Point” for an example usage.
Example 19.5. Creating a Slave Mount Point
This example shows how to get the content of the findmnt directory; echo $?08 directory to appear in findmnt directory; echo $?09 as well, but without any mounts in the findmnt directory; echo $?09 directory to be reflected in findmnt directory; echo $?08. As $ mount -t type device directory6, first mark the findmnt directory; echo $?08 directory as shared:
findmnt directory; echo $?9Then create its duplicate in findmnt directory; echo $?09, but mark it as "slave":
mount [option…] directory mount [option…] device0Now verify that a mount within findmnt directory; echo $?08 also appears in findmnt directory; echo $?09. For example, if the CD-ROM drive contains non-empty media and the findmnt directory; echo $?05 directory exists, run the following commands:
mount [option…] directory mount [option…] device1Also verify that file systems mounted in the findmnt directory; echo $?09 directory are not reflected in findmnt directory; echo $?08. For instance, if a non-empty USB flash drive that uses the # mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom4 device is plugged in and the findmnt directory; echo $?19 directory is present, type:
mount [option…] directory mount [option…] device2Private MountA 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 [option…] directory mount [option…] device3Alternatively, it is possible to change the mount type for the selected mount point and all mount points under it:
mount [option…] directory mount [option…] device4See Example 19.6, “Creating a Private Mount Point” for an example usage.
Example 19.6. Creating a Private Mount Point
Taking into account the scenario in Example 19.4, “Creating a Shared Mount Point”, assume that a shared mount point has been previously created by using the following commands as $ mount -t type device directory6:
mount [option…] directory mount [option…] device5To mark the findmnt directory; echo $?09 directory as private, type:
mount [option…] directory mount [option…] device6It is now possible to verify that none of the mounts within findmnt directory; echo $?08 appears in findmnt directory; echo $?09. For example, if the CD-ROM drives contains non-empty media and the findmnt directory; echo $?05 directory exists, run the following commands:
mount [option…] directory mount [option…] device7It is also possible to verify that file systems mounted in the findmnt directory; echo $?09 directory are not reflected in findmnt directory; echo $?08. For instance, if a non-empty USB flash drive that uses the # mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom4 device is plugged in and the findmnt directory; echo $?19 directory is present, type:
mount [option…] directory mount [option…] device2Unbindable MountIn 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 [option…] directory mount [option…] device9Alternatively, it is possible to change the mount type for the selected mount point and all mount points under it:
blkid device0See Example 19.7, “Creating an Unbindable Mount Point” for an example usage.
Example 19.7. Creating an Unbindable Mount Point
To prevent the findmnt directory; echo $?08 directory from being shared, as $ mount -t type device directory6:
blkid device1This way, any subsequent attempt to make a duplicate of this mount fails with an error:
blkid device219.2.4. Moving a Mount Point
To change the directory in which a file system is mounted, use the following command:
blkid device3See Example 19.8, “Moving an Existing NFS Mount Point” for an example usage.
Example 19.8. Moving an Existing NFS Mount Point
An NFS storage contains user directories and is already mounted in findmnt directory; echo $?45. As $ mount -t type device directory6, move this mount point to findmnt directory; echo $?47 by using the following command:
blkid device4To verify the mount point has been moved, list the content of both directories:
blkid device519.2.5. Setting Read-only Permissions for $ mount -t type device directory6
Sometimes, you need to mount the root file system with read-only permissions. Example use cases include enhancing security or ensuring data integrity after an unexpected system power-off.
19.2.5.1. Configuring $ mount -t type device directory6 to Mount with Read-only Permissions on Boot
In the findmnt directory; echo $?50 file, change findmnt directory; echo $?51 to findmnt directory; echo $?52:
blkid device6Change $ mount --bind old_directory new_directory1 to findmnt directory; echo $?01 in the root entry (findmnt directory; echo $?55) in the $ mount -t type device directory3 file:
blkid device7Add findmnt directory; echo $?01 to the findmnt directory; echo $?58 directive in the findmnt directory; echo $?59 file and ensure that it does not contain findmnt directory; echo $?02:
blkid device8Recreate the GRUB2 configuration file:
blkid device9If you need to add files and directories to be mounted with write permissions in the findmnt directory; echo $?61 file system, create a text file in the findmnt directory; echo $?62 directory and put the configuration there. For example, to mount findmnt directory; echo $?63 with write permissions, add this line to the findmnt directory; echo $?64 file:
# blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3" 0Important
Changes made to files and directories in findmnt directory; echo $?61 do not persist across boots.
See Section 19.2.5.3, “Files and Directories That Retain Write Permissions” for more information on this step.
Reboot the system.
19.2.5.2. Remounting $ mount -t type device directory6 Instantly
If root (findmnt directory; echo $?55) was mounted with read-only permissions on system boot, you can remount it with write permissions:
# blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3" 1This can be particularly useful when findmnt directory; echo $?55 is incorrectly mounted with read-only permissions.
To remount findmnt directory; echo $?55 with read-only permissions again, run:
# blkid /dev/sda3 /dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3" 2Note
This command mounts the whole findmnt directory; echo $?55 with read-only permissions. A better approach is to retain write permissions for certain files and directories by copying them into RAM, as described in Section 19.2.5.1, “Configuring $ mount -t type device directory6 to Mount with Read-only Permissions on Boot”.
19.2.5.3. Files and Directories That Retain Write Permissions
For the system to function properly, some files and directories need to retain write permissions. With root in read-only mode, they are mounted in RAM in the findmnt directory; echo $?61 temporary file system. The default set of such files and directories is read from the findmnt directory; echo $?73 file, which contains: