Using the Mount and Unmount File Systems Commands on Linux

On Linux and UNIX operating systems, you can use the . command mount To mount system files and removable devices such as USB flash drives at specific mount points in the directory tree.

ranking umount It means to unpack the attached file system from the directory tree.

In this tutorial, we’ll cover the basics of attaching and unmounting different file systems with the command mount And the umount .

How to list available file systems

When used without any arguments, the command mount It will display all currently attached file systems:


By default, the output will include all file systems including default ones like cgroup, sysfs, etc. Each line includes information about the device name, the directory in which the device is installed, file system type, and installation options.

To show only certain file systems, use the -t option.

For example, to print only the ext4 partition you are using

mount -t ext4

File system installation

To mount (attach) a file system to a specified location (mount point), use the mount command as follows:


Once the file system is installed, the mount point becomes the root directory of the attached file system.

For example, to mount the file system /dev/sdb2 for proof /mnt/media, Then the command you will use:

sudo mount /dev/sdb1 /mnt/media

Usually when you mount a device with a common file system like ext4 or xfs, the mount command will detect the type of file system automatically. However, there are some file systems that are not recognized and need to be specified explicitly.

See also  How to install and configure Anaconda on CentOS 7

Use the -t option to specify the file system type:


To specify additional mounting options, use the -o option:


Multiple options can be included in the command and separated by commas (don’t put a space after the comma).

You can get a list of all mount options by typing man mount in your terminal.

Mounting the file system using /etc/fstab

When only one parameter (manual or device) is passed to a command mountwill read the contents of the configuration file /etc/fstab Checks if the specified file system exists or is registered in the system.

if /etc/fstab Contains information about a particular command or file system mount You will fill in the values ​​of other parameters and use the options mount specified in the fstab file.

a file /etc/fstab It contains the list of entries as follows:

[File System] [Mount Point] [File System Type] [Options] [Dump] [Pass]

Use the command mount In one of the following forms to attach the file system specified in the file /etc/fstab:


USB drive installation

On most modern Linux distributions like Ubuntu, the USB drive will mount automatically when you insert it, but if something goes wrong, you may need to mount the drive manually.

To manually connect a USB device, use the following steps:

  1. Create installation points:
    sudo mkdir -p /media/usb
  2. Assuming a USB drive is used/dev/sdb1 You can download the USB to the directory /media/usb By writing:
    sudo mount /dev/sdb1 /media/usb

    To find the device type and file system, you can use one of the following commands:

    fdisk -l
    ls -l /dev/disk/by-id/usb*

To mount an exFAT USB drive, you will need to install the freely available exFAT FUSE module and tool.

See also  How to install and configure Mono on CentOS 8

Install ISO files

We can mount the ISO file using the loop device. The loop Device is a special pseudo-device that makes files accessible as block devices.

  1. Start by creating a mount point, this mount point will be anywhere you want:
    sudo mkdir /media/iso
  2. Mount the ISO file to the mount point by typing the following command:
    sudo mount /path/ke/image.iso /mnt/iso -o loop

    Don’t forget to replace /path/ke/image.iso With the path to where your ISO file is saved.

Mount NFS

To mount an NFS system, you must install the Client for NFS package on your system.

  • Install Client for NFS on Ubuntu and Debian
    sudo apt install nfs-common
  • Install Client for NFS on CentOS and Fedora:
    sudo yum install nfs-utils

Use the steps below to mount a remote NFS directory on your system:

  1. Create a directory to serve as a mount point for the remote file system:
    sudo mkdir /media/nfs
  2. In general, you want remote NFS directories to mount automatically on boot. To do this open the file /etc/fstab Using your text editor:
    sudo nano /etc/fstab

    Add the following line to the file, replacing remote.server:/dir With the NFS server IP address or the source hostname and directory:

    # <file system>    <dir>       <type>   <options>   <dump>	<pass>
    remote.server:/dir /media/nfs  nfs      defaults    0       0
  3. Mount the NFS share by running the following command:
    sudo mount /mnt/nfs

Decompile the file system

To unmount the mounted file system, use the command umount followed by the directory in which it is installed (mounting point) or the name of the device


If the file system is in use, the command umount It will fail to detach the file system. In this case, you can use the command fuser To find out which process is accessing the file system:

fuser -m DIRECTORY

Once the process is identified, you can stop it and unmount the file system.

See also  A tutorial on configuring Apache Virtual Hosts on CentOS 8

lazy jaw

Use option -l (--lazy) to unmount a busy file system, this option will be activated as soon as the mounted device becomes unoccupied.

umount -l DIRECTORY

jaw force

Use option -f (--force) to force the jaw. This option is typically used to offload an NFS system that is no longer responding or cannot be reached (usually timed out on the network).

umount -f DIRECTORY

It is generally not a good idea to force an unmount because it can corrupt the data on the file system.


By now you should have a good understanding of how to use commands mount To attach different file systems to the directory tree and unmount them with the . command umount .

Learn more about command options mount And the umount See the manual page related to the manual page in the Linux terminal.

Source link