Access the contents of file systems by adding and removing file systems in the file-system hierarchy.
To access the file system on a removable storage device, you must mount the storage device.
With the mount command, the root user can mount a file system manually.
The first argument of the mount command specifies the file system to mount.
The second argument specifies the directory as the mount point in the file-system hierarchy.
You can mount the file system in one of the following ways with the mount command:
With the device file name in the /dev directory.
With the UUID, a universally unique identifier of the device.
Then, identify the device to mount, ensure that the mount point exists, and mount the device on the mount point.
If you mount a file system with the mount command, and then reboot your system, the file system is not automatically remounted.
The Red Hat System Administration II (RH134) course explains how to persistently mount file systems with the /etc/fstab file.
A hot-pluggable storage device, whether a hard disk drive (HDD) or a solid-state device (SSD) in a server, or alternatively a USB storage device, might be plugged each time into a different port on a system.
Use the lsblk command to list the details of a specified block device or of all the available devices.
[root@host ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
vda 252:0 0 10G 0 disk
├─vda1 252:1 0 1M 0 part
├─vda2 252:2 0 200M 0 part /boot/efi
├─vda3 252:3 0 500M 0 part /boot
└─vda4 252:4 0 9.3G 0 part /
vdb 252:16 0 5G 0 disk
vdc 252:32 0 5G 0 disk
vdd 252:48 0 5G 0 diskThe partition size helps to identify the device when the partition name is unknown.
For example, considering the previous output, if the size of the identified partition is 9.3 GB, then mount the /dev/vda4 partition.
The following example mounts the /dev/vda4 partition on the /mnt/data mount point.
[root@host ~]# mount /dev/vda4 /mnt/dataThe mount point directory must exist before mounting the file system.
The /mnt directory exists for use as a temporary mount point.
If a directory to use as a mount point is not empty, then the existing files are hidden and not accessible when a file system is mounted there. The original files are accessible again after the mounted file system is unmounted.
Device detection order and storage device naming can change when devices are added or removed on a system. It is recommended to use an unchanging device identifier to mount file systems consistently.
One stable identifier that is associated with a file system is its universally unique identifier (UUID). This UUID is stored in the file system superblock and remains the same until the file system is re-created.
The lsblk -fp command lists the full path of the device, the UUIDs and mount points, and the partition's file-system type.
The mount point is blank when the file system is not mounted.
[root@host ~]# lsblk -fp
NAME FSTYPE FSVER LABEL UUID FSAVAIL FSUSE% MOUNTPOINTS
/dev/vda
├─/dev/vda1
├─/dev/vda2 vfat FAT16 7B77-95E7 192.3M 4% /boot/efi
├─/dev/vda3 xfs boot 2d67e6d0-...-1f091bf1 334.9M 32% /boot
└─/dev/vda4 xfs root efd314d0-...-ae98f652 7.7G 18% /
/dev/vdb
/dev/vdc
/dev/vddMount the file system by the file-system UUID.
[root@host ~]# mount UUID="efd314d0-b56e-45db-bbb3-3f32ae98f652" /mnt/dataWith the graphical desktop environment, the system automatically mounts removable storage media when the media presence is detected.
The removable storage device mounts at the /run/media/ location.
USERNAME is the name of the user that is logged in to the graphical environment.
LABEL is an identifier, which is typically the label on the storage media.USERNAME/LABEL
To safely detach a removable device, manually unmount all file systems on the device first.
System shutdown and reboot procedures unmount all file systems automatically. All file-system data is flushed to the storage device, to ensure file-system data integrity.
File-system data uses memory cache during normal operation. You must unmount a removable drive's file systems before unplugging the drive. The unmount procedure flushes data to disk before releasing the drive.
The umount command uses the mount point as an argument to unmount a file system.
[root@host ~]# umount /mnt/dataUnmounting is not possible when the mounted file system is in use.
For the umount command to succeed, all processes must stop accessing data under the mount point.
In the following example, the umount command fails because the shell uses the /mnt/data directory as its current working directory, and thus generates an error message.
[root@host ~]#cd /mnt/data[root@host data]#umount /mnt/dataumount: /mnt/data: target is busy.
The lsof command lists all open files and the processes that are accessing the file system.
The list helps to identify which processes are preventing the file system from successfully unmounting.
[root@host data]# lsof /mnt/data
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bash 1593 root cwd DIR 253,17 6 128 /mnt/data
lsof 2532 root cwd DIR 253,17 19 128 /mnt/data
lsof 2533 root cwd DIR 253,17 19 128 /mnt/dataIdentify and wait for the processes to complete, or send the SIGTERM or SIGKILL signal to terminate them.
In this case, it is sufficient to change to a current working directory that is outside the mount point.
[root@host data]#cd[root@host ~]#umount /mnt/data