Using the mount
Command
WARNING:
This documentation is a draft and is not meant for production use. Branch: OL10-FSADMIN
Use the mount
command to attach the device containing the file
system to the mount point as follows:
sudo mount [options] device mount_point
The device can be mounted by referencing its name, UUID, or label. For example, any of the following mount commands are appropriate:
sudo mount /dev/sdb1 /mnt
sudo mount UUID="ad8113d7-b279-4da8-b6e4-cfba045f66ff" /mnt
sudo mount LABEL="Projects" /mnt
The mount_point must exist as a directory within an existing file system. Typically the mount point is an empty directory, but if it isn't empty the contents of the directory aren't accessible while a device is mounted onto it.
Options
The following options are commonly used when mounting file systems. For more
comprehensive coverage of available options, see the mount(8)
manual page.
-
auto
-
Causes the file system to be mounted automatically by using the
mount -a
command. -
exec
-
Allows the execution of any binary files in the file system.
-
loop
-
Uses a loop device (
/dev/loop*
) to mount a file that contains a file system image. Seelosetup(8)
manual page. See alsoUsing the loop Device to Mount a File System ImageNote:
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. Or, add the following entry to/etc/modprobe.conf
:options loop max_loop=N
In the previous example, N is the number of loop devices that you require (from 0 to 255), and then reboot the system.
-
noauto
-
Prevents the file system from being mounted automatically when
mount -a
is issued. -
noexec
-
Prevents the execution of any binary files in the file system.
-
nouser
-
Prevents any user other than the
root
user from mounting or unmounting the file system. -
remount
-
Remounts the file system if it's already mounted. You would typically combine this option with another option such as
ro
orrw
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.
Example 3-1 Mount a Device With Read-Only Access
Mount the /dev/sdd1
device onto the mount point
/test
with read-only access and grant only the
root
user to mount or unmount the file system:
sudo mount -o nouser,ro /dev/sdd1 /test
Example 3-2 Mount an ISO Image
Mount an ISO image file onto the mount point /media/cdrom
with
read-only access by using the loop device:
sudo mount -o ro,loop ./Oracle_Linux.iso /media/cdrom
Example 3-3 Remount a File System With Read-Write Access and Prevent Running of Binary Files
Remount the /test
file system with both read and write access, and
prohibit the running of any binary files that are in the file system:
sudo mount -o remount,rw,noexec /test
Using Bind Mounts
A bind mount can be used to remount a directory or file at another location in the file system hierarchy.
Bind mounts are commonly used to expose data from an underlying file system to chroot or container environments. Bind mounts are also useful when working with applications that might expect data to appear in alternative locations on a file system.
Each directory hierarchy acts as a mirror of the other. The same files are accessible in either location.
For a standard bind mount, any submounts aren't replicated. You can also use a recursive bind mount to replicate any submounts within the new mount location.
The mount command also includes options to prevent a bind on a mount point, to share mount actions for submounts between mirrors.
The mirrors that are created by using bind mounts don't provide data redundancy.
Using the loop
Device to Mount a File System Image
You can create a file system image within an existing file system and mount the file
system image by using a loop
device.
A loop device lets you access a file as a block device. For example, you can mount a
file that contains a DVD ISO image on the directory mount point
/ISO
as follows:
sudo mount -t iso9660 -o loop /tmp/OracleLinux.iso /ISO
The mount command can detect the file system type and understands that when you're
mounting a file image to a mount point, a loop device is intended. Therefore, you
can also run the mount command without specifying the -t
and
-o
options:
sudo mount /tmp/OracleLinux.iso /ISO
You can also create a file system image with an alternative file system within an existing file system. The following procedure describes how to create an empty file, format it with a file system and then mount it using a loop device.
Moving a File System to a New Mount Point
You can move a file system mounted at a mount point to a new mount point by using the mount --move
command.
The mount --move
command. can move a file system from one mount point to another without unmounting it.
Moving the file system can be useful if you need to switch mount points without interrupting processes that are running and accessing files. Moves are more commonly performed in early stage boot processes, or in containerized. environments. The move operation removes the original mount after the file system is moved to the new target. If a process has an open file based on the original mount point, the process is unaffected because the file descriptor points to the inode and not the path, and the file system continues to be available because it's not unmounted during the move operation.