19.2. Mounting a File System
			To attach a certain file system, use the 
mount command in the following form:
		mount [option…] device directory
$ mount [option…] device directory
			The device can be identified by:
		
- a full path to a block device: for example,/dev/sda3
- a universally unique identifier (UUID): for example,UUID=34795a28-ca6d-4fd8-a347-73671d0c19cb
- a volume label: for example,LABEL=home
			Note that while a file system is mounted, the original content of the directory is not accessible.
		
Important
				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 
findmnt utility with the directory as its argument and verify the exit code:
			findmnt directory; echo $?
findmnt directory; echo $?
				If no file system is attached to the directory, the given command returns 
1.
			
			When you run the 
mount command without all required information, that is without the device name, the target directory, or the file system type, the mount reads the contents of the /etc/fstab file to check if the given file system is listed. The /etc/fstab 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 /etc/fstab, you can choose one of the following options:
		mount [option…] directory mount [option…] device
mount [option…] directory
mount [option…] device
			Note that permissions are required to mount the file systems unless the command is run as 
root (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 
blkid command in the following form:
			blkid device
blkid device
				For example, to display information about 
/dev/sda3:
			blkid /dev/sda3
# blkid /dev/sda3
/dev/sda3: LABEL="home" UUID="34795a28-ca6d-4fd8-a347-73671d0c19cb" TYPE="ext3"
19.2.1. Specifying the File System Type
Copy linkLink copied to clipboard!
				In most cases, 
mount detects the file system automatically. However, there are certain file systems, such as NFS (Network File System) or CIFS (Common Internet File System), that are not recognized, and need to be specified manually. To specify the file system type, use the mount command in the following form:
			mount -t type device directory
$ mount -t type device directory
				Table 19.1, “Common File System Types” provides a list of common file system types that can be used with the 
mount command. For a complete list of all available file system types, see the section called “Manual Page Documentation”.
			| Type | Description | 
|---|---|
| ext2 | The ext2file system. | 
| ext3 | The ext3file system. | 
| ext4 | The ext4file system. | 
| btrfs | The btrfsfile system. | 
| xfs | The xfsfile system. | 
| iso9660 | The ISO 9660file system. It is commonly used by optical media, typically CDs. | 
| nfs | The NFSfile system. It is commonly used to access files over the network. | 
| nfs4 | The NFSv4file system. It is commonly used to access files over the network. | 
| udf | The UDFfile system. It is commonly used by optical media, typically DVDs. | 
| vfat | The FATfile 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 
/dev/sdc1 device and that the /media/flashdisk/ directory exists, mount it to this directory by typing the following at a shell prompt as root:
				mount -t vfat /dev/sdc1 /media/flashdisk
~]# mount -t vfat /dev/sdc1 /media/flashdisk19.2.2. Specifying the Mount Options
Copy linkLink copied to clipboard!
				To specify additional mount options, use the command in the following form:
			
mount -o options device directory
mount -o options device directory
				When supplying multiple options, do not insert a space after a comma, or 
mount 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”.
			
| Option | Description | 
|---|---|
| async | Allows the asynchronous input/output operations on the file system. | 
| auto | Allows the file system to be mounted automatically using the mount -acommand. | 
| defaults | Provides an alias for async,auto,dev,exec,nouser,rw,suid. | 
| exec | Allows the execution of binary files on the particular file system. | 
| loop | Mounts an image as a loop device. | 
| noauto | Default behavior disallows the automatic mount of the file system using the mount -acommand. | 
| noexec | Disallows the execution of binary files on the particular file system. | 
| nouser | Disallows an ordinary user (that is, other than root) to mount and unmount the file system. | 
| remount | Remounts the file system in case it is already mounted. | 
| ro | Mounts the file system for reading only. | 
| rw | Mounts the file system for both reading and writing. | 
| user | Allows an ordinary user (that is, other than root) 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 
/media/cdrom/ 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/cdrom
# mount -o ro,loop Fedora-14-x86_64-Live-Desktop.iso /media/cdrom
					Note that ISO 9660 is by design a read-only file system.
				
19.2.3. Sharing Mounts
Copy linkLink copied to clipboard!
				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 --bind old_directory new_directory
$ mount --bind 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, use the following command:
			
mount --rbind old_directory new_directory
$ mount --rbind 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:
			
- 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-shared mount_point $ mount --make-shared mount_pointCopy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, to change the mount type for the selected mount point and all mount points under it:mount --make-rshared mount_point $ mount --make-rshared mount_pointCopy to Clipboard Copied! Toggle word wrap Toggle overflow See Example 19.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-slave mount_point mount --make-slave mount_pointCopy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, it is possible to change the mount type for the selected mount point and all mount points under it by typing:mount --make-rslave mount_point mount --make-rslave mount_pointCopy to Clipboard Copied! Toggle word wrap Toggle overflow See 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/media/directory to appear in/mnt/as well, but without any mounts in the/mnt/directory to be reflected in/media/. Asroot, first mark the/media/directory as shared:mount --bind /media /media mount --make-shared /media ~]# mount --bind /media /media ~]# mount --make-shared /mediaCopy to Clipboard Copied! Toggle word wrap Toggle overflow Then create its duplicate in/mnt/, but mark it as "slave":mount --bind /media /mnt mount --make-slave /mnt ~]# mount --bind /media /mnt ~]# mount --make-slave /mntCopy to Clipboard Copied! Toggle word wrap Toggle overflow Now verify that a mount within/media/also appears in/mnt/. For example, if the CD-ROM drive contains non-empty media and the/media/cdrom/directory exists, run the following commands:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Also verify that file systems mounted in the/mnt/directory 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/flashdisk ~]# mount /dev/sdc1 /mnt/flashdisk ~]# ls /media/flashdisk ~]# ls /mnt/flashdisk en-US publican.cfgCopy to Clipboard Copied! Toggle word wrap Toggle overflow 
- 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-private mount_point mount --make-private mount_pointCopy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, it is possible to change the mount type for the selected mount point and all mount points under it:mount --make-rprivate mount_point mount --make-rprivate mount_pointCopy to Clipboard Copied! Toggle word wrap Toggle overflow See 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 asroot:mount --bind /media /media mount --make-shared /media mount --bind /media /mnt ~]# mount --bind /media /media ~]# mount --make-shared /media ~]# mount --bind /media /mntCopy to Clipboard Copied! Toggle word wrap Toggle overflow To mark the/mnt/directory as private, type:mount --make-private /mnt ~]# mount --make-private /mntCopy to Clipboard Copied! Toggle word wrap Toggle overflow It is now possible to verify that none of the mounts within/media/appears in/mnt/. For example, if the CD-ROM drives contains non-empty media and the/media/cdrom/directory exists, run the following commands:Copy to Clipboard Copied! Toggle word wrap Toggle overflow It is also possible to verify that file systems mounted in the/mnt/directory 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/flashdisk ~]# mount /dev/sdc1 /mnt/flashdisk ~]# ls /media/flashdisk ~]# ls /mnt/flashdisk en-US publican.cfgCopy to Clipboard Copied! Toggle word wrap Toggle overflow 
- 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-unbindable mount_point mount --make-unbindable mount_pointCopy to Clipboard Copied! Toggle word wrap Toggle overflow Alternatively, it is possible to change the mount type for the selected mount point and all mount points under it:mount --make-runbindable mount_point mount --make-runbindable mount_pointCopy to Clipboard Copied! Toggle word wrap Toggle overflow See Example 19.7, “Creating an Unbindable Mount Point” for an example usage.Example 19.7. Creating an Unbindable Mount Point To prevent the/media/directory from being shared, asroot:mount --bind /media /media mount --make-unbindable /media # mount --bind /media /media # mount --make-unbindable /mediaCopy to Clipboard Copied! Toggle word wrap Toggle overflow This way, any subsequent attempt to make a duplicate of this mount fails with an error:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 
19.2.4. Moving a Mount Point
Copy linkLink copied to clipboard!
				To change the directory in which a file system is mounted, use the following command:
			
mount --move old_directory new_directory
# mount --move old_directory new_directory
				See 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 
/mnt/userdirs/. As root, move this mount point to /home by using the following command:
				mount --move /mnt/userdirs /home
# mount --move /mnt/userdirs /home
					To verify the mount point has been moved, list the content of both directories:
				
ls /mnt/userdirs ls /home
# ls /mnt/userdirs
# ls /home
jill  joe
19.2.5. Setting Read-only Permissions for root
Copy linkLink copied to clipboard!
				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 root to Mount with Read-only Permissions on Boot
Copy linkLink copied to clipboard!
- In the/etc/sysconfig/readonly-rootfile, changeREADONLYtoyes:Set to 'yes' to mount the file systems as read-only. # Set to 'yes' to mount the file systems as read-only. READONLY=yes [output truncated]Copy to Clipboard Copied! Toggle word wrap Toggle overflow 
- Changedefaultstoroin the root entry (/) in the/etc/fstabfile:/dev/mapper/luks-c376919e... / ext4 ro,x-systemd.device-timeout=0 1 1 /dev/mapper/luks-c376919e... / ext4 ro,x-systemd.device-timeout=0 1 1Copy to Clipboard Copied! Toggle word wrap Toggle overflow 
- Addroto theGRUB_CMDLINE_LINUXdirective in the/etc/default/grubfile and ensure that it does not containrw:GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet ro" GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=rhel/root rd.lvm.lv=rhel/swap rhgb quiet ro"Copy to Clipboard Copied! Toggle word wrap Toggle overflow 
- Recreate the GRUB2 configuration file:grub2-mkconfig -o /boot/grub2/grub.cfg # grub2-mkconfig -o /boot/grub2/grub.cfgCopy to Clipboard Copied! Toggle word wrap Toggle overflow 
- If you need to add files and directories to be mounted with write permissions in thetmpfsfile system, create a text file in the/etc/rwtab.d/directory and put the configuration there. For example, to mount/etc/example/filewith write permissions, add this line to the/etc/rwtab.d/examplefile:files /etc/example/file files /etc/example/fileCopy to Clipboard Copied! Toggle word wrap Toggle overflow Important Changes made to files and directories intmpfsdo 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 root Instantly
Copy linkLink copied to clipboard!
					If root (
/) was mounted with read-only permissions on system boot, you can remount it with write permissions:
				mount -o remount,rw /
# mount -o remount,rw /
					This can be particularly useful when 
/ is incorrectly mounted with read-only permissions.
				
					To remount 
/ with read-only permissions again, run:
				mount -o remount,ro /
# mount -o remount,ro /Note
						This command mounts the whole 
/ 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 root to Mount with Read-only Permissions on Boot”.
					19.2.5.3. Files and Directories That Retain Write Permissions
Copy linkLink copied to clipboard!
					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 
tmpfs temporary file system. The default set of such files and directories is read from the /etc/rwtab file, which contains:
				
					Entries in the 
/etc/rwtab file follow this format:
				how the file or directory is copied to tmpfs path to the file or directory
how the file or directory is copied to tmpfs       	path to the file or directory
					A file or directory can be copied to 
tmpfs in the following three ways:
				- empty path: An empty path is copied to- tmpfs. Example:- empty /tmp
- dirs path: A directory tree is copied to- tmpfs, empty. Example:- dirs /var/run
- files path: A file or a directory tree is copied to- tmpfsintact. Example:- files /etc/resolv.conf
					The same format applies when adding custom paths to 
/etc/rwtab.d/.