19.2. Mounting a File System
mount command in the following form:
$mount[option…] device directory
- 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
Important
findmnt utility with the directory as its argument and verify the exit code:
findmntdirectory;echo$?
1.
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…] directorymount[option…] device
root (see Section 19.2.2, “Specifying the Mount Options”).
Note
blkid command in the following form:
blkid device/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
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 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
| Type | Description |
|---|---|
ext2 | The ext2 file system. |
ext3 | The ext3 file system. |
ext4 | The ext4 file system. |
btrfs | The btrfs file system. |
xfs | The xfs file system. |
iso9660 | The ISO 9660 file system. It is commonly used by optical media, typically CDs. |
jfs | The JFS file system created by IBM. |
nfs | The NFS file system. It is commonly used to access files over the network. |
nfs4 | The NFSv4 file system. It is commonly used to access files over the network. |
ntfs | The NTFS file system. It is commonly used on machines that are running the Windows operating system. |
udf | The UDF file system. It is commonly used by optical media, typically DVDs. |
vfat | The FAT 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. |
Example 19.2. Mounting a USB Flash Drive
/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/flashdisk19.2.2. Specifying the Mount Options
mount-ooptions device directory
mount interprets incorrectly the values following spaces as additional parameters.
Table 19.2. Common Mount Options
| 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 -a command. |
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 -a command. |
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. |
Example 19.3. Mounting an ISO Image
/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
19.2.3. Sharing Mounts
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 --rbind old_directory new_directory
- 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_pointAlternatively, to change the mount type for the selected mount point and all mount points under it:$mount --make-rshared mount_pointSee 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-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 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 /mediaThen create its duplicate in/mnt/, but mark it as "slave":~]#
mount --bind /media /mnt~]#mount --make-slave /mntNow 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:~]#
mount /dev/cdrom /media/cdrom~]#ls /media/cdromEFI GPL isolinux LiveOS ~]#ls /mnt/cdromEFI GPL isolinux LiveOSAlso 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/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 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 /mntTo mark the/mnt/directory as private, type:~]#
mount --make-private /mntIt 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:~]#
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/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/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 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 /mediaThis way, any subsequent attempt to make a duplicate of this mount fails 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
19.2.4. Moving a Mount Point
#mount --move old_directory new_directory
Example 19.8. Moving an Existing NFS Mount Point
/mnt/userdirs/. As root, move this mount point to /home by using the following command:
#mount --move /mnt/userdirs /home
#ls /mnt/userdirs#ls /homejill joe
19.2.5. Setting Read-only Permissions for root
19.2.5.1. Configuring root to Mount with Read-only Permissions on Boot
- In the
/etc/sysconfig/readonly-rootfile, changeREADONLYtoyes:# Set to 'yes' to mount the file systems as read-only. READONLY=yes [output truncated] - Change
defaultstoroin the root entry (/) in the/etc/fstabfile:/dev/mapper/luks-c376919e... / ext4 ro,x-systemd.device-timeout=0 1 1 - Add
roto 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" - Recreate the GRUB2 configuration file:
#grub2-mkconfig -o /boot/grub2/grub.cfg - If you need to add files and directories to be mounted with write permissions in the
tmpfsfile 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
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
/) was mounted with read-only permissions on system boot, you can remount it with write permissions:
#mount -o remount,rw /
/ is incorrectly mounted with read-only permissions.
/ with read-only permissions again, run:
#mount -o remount,ro /
Note
/ 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
tmpfs temporary file system. The default set of such files and directories is read from the /etc/rwtab file, which contains:
dirs /var/cache/man dirs /var/gdm [output truncated] empty /tmp empty /var/cache/foomatic [output truncated] files /etc/adjtime files /etc/ntp.conf [output truncated]
/etc/rwtab file follow this format:
how the file or directory is copied to tmpfs path to the file or directory
tmpfs in the following three ways:
empty path: An empty path is copied totmpfs. Example:empty /tmpdirs path: A directory tree is copied totmpfs, empty. Example:dirs /var/runfiles path: A file or a directory tree is copied totmpfsintact. Example:files /etc/resolv.conf
/etc/rwtab.d/.

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.