17.2 Mounting File Systems

17.2.1 About Mount Options

To access a file system's contents, you must attach its block device to a mount point in the directory hierarchy. You can use the mkdir command to create a directory for use as a mount point, for example:

# mkdir /var/projects

You can use an existing directory as a mount point, but its contents are hidden until you unmount the overlying file system.

The mount command attaches the device containing the file system to the mount point:

# mount [options] device mount_point

You can specify the device by its name, UUID, or label. For example, the following commands are equivalent ways of mounting the file system on the block device /dev/sdb1:

# mount /dev/sdb1 /var/projects
# mount UUID="ad8113d7-b279-4da8-b6e4-cfba045f66ff" /var/projects
# mount LABEL="Projects" /var/projects

If you do not specify any arguments, mount displays all file systems that the system currently has mounted, for example:

# mount
/dev/mapper/vg_host01-lv_root on / type ext4 (rw)
...

In this example, the LVM logical volume /dev/mapper/vg_host01-lv_root is mounted on /. The file system type is ext4 and is mounted for both reading and writing. (You can also use the command cat /proc/mounts to display information about mounted file systems.)

The df command displays information about home much space remains on mounted file systems, for example:

# df -h
Filesystem                     Size  Used Avail Use% Mounted on
/dev/mapper/vg_host01-lv_root  36G   12G   22G  36% /
...

You can use the -B (bind) option to the mount command to attach a block device at multiple mount points. You can also remount part of a directory hierarchy, which need not be a complete file system, somewhere else. For example, the following command mounts /var/projects/project1 on /mnt:

# mount -B /var/projects/project1 /mnt

Each directory hierarchy acts as a mirror of the other. The same files are accessible in either location, although any submounts are not replicated. These mirrors do not provide data redundancy.

You can also mount a file over another file, for example:

# touch /mnt/foo
# mount -B /etc/hosts /mnt/foo

In this example, /etc/hosts and /mnt/foo represent the same file. The existing file that acts as a mount point is not accessible until you unmount the overlying file.

The -B option does not recursively attach any submounts below a directory hierarchy. To include submounts in the mirror, use the -R (recursive bind) option instead.

When you use -B or -R, the file system mount options remain the same as those for the original mount point. To modify, the mount options, use a separate remount command, for example:

# mount -o remount,ro /mnt/foo

You can mark the submounts below a mount point as being shared, private, or slave:

mount --make-shared mount_point

Any mounts or unmounts below the specified mount point propagate to any mirrors that you create, and this mount hierarchy reflects mounts or unmount changes that you make to other mirrors.

mount --make-private mount_point

Any mounts or unmounts below the specified mount point do not propagate to other mirrors, nor does this mount hierarchy reflect mounts or unmount changes that you make to other mirrors.

mount --make-slave mount_point

Any mounts or unmounts below the specified mount point do not propagate to other mirrors, but this mount hierarchy does reflect mounts or unmount changes that you make to other mirrors.

To prevent a mount from being mirrored by using the -B or -R options, mark its mount point as being unbindable:

# mount --make-unbindable mount_point

To move a mounted file system, directory hierarchy, or file between mount points, use the -M option, for example:

# touch /mnt/foo
# mount -M /mnt/foo /mnt/bar

To unmount a file system, use the umount command, for example:

# umount /var/projects

Alternatively, you can specify the block device provided that it is mounted on only one mount point.

For more information, see the mount(8) and umount(8) manual pages.

17.2.1 About Mount Options

To modify the behavior of mount, use the –o flag followed by a comma-separated list of options or specify the options in the /etc/fstab file. The following are some of the options that are available:

auto

Allows the file system to be mounted automatically by using the mount –a command.

exec

Allows the execution of any binary files located in the file system.

loop

Uses a loop device (/dev/loop*) to mount a file that contains a file system image. See Section 17.5, “Mounting a File Containing a File System Image”, Section 17.6, “Creating a File System on a File”, and the losetup(8) manual page.

Note

The default number of available loop devices is 8. You can use the kernel boot parameter max_loop=N to configure up to 255 devices. Alternatively, add the following entry to /etc/modprobe.conf:

options loop max_loop=N

where N is the number of loop devices that you require (from 0 to 255), and reboot the system.

noauto

Disallows the file system from being mounted automatically by using mount –a.

noexec

Disallows the execution of any binary files located in the file system.

nouser

Disallows any user other than root from mounting or unmounting the file system.

remount

Remounts the file system if it is already mounted. You would usually combine this option with another option such as ro or rw to change the behavior of a mounted file system.

ro

Mounts a file system as read-only.

rw

Mounts a file system for reading and writing.

user

Allows any user to mount or unmount the file system.

For example, mount /dev/sdd1 as /test with read-only access and only root permitted to mount or unmount the file system:

# mount –o nouser,ro /dev/sdd1 /test

Mount an ISO image file on /mount/cdrom with read-only access by using the loop device:

# mount -o ro,loop ./OracleLinux-R6-U1-Server-x86_64-dvd.iso /media/cdrom

Remount the /test file system with both read and write access, but do not permit the execution of any binary files that are located in the file system:

# mount -o remount,rw,noexec /test