Read in 5 minutes
How to Mount and Unmount File Systems in Linux
On Linux and UNIX operating systems you can use the
mount command to attach (mount) file systems and removable devices such as USB flash drives at a particular mount point in the directory tree.
umount command detaches (unmounts) the mounted file system from the directory tree.
In this tutorial we will go over the basics of attaching and detaching various file systems using the
How to List Mounted File Systems
When used without any argument, the
mount command will display all currently attached file systems:
By default, the output will include all file systems including the virtual ones such as cgroup, sysfs, and others. Each line includes information about the device name, the directory in which the device is mounted, the type of the filesystem and the mount options in the following form:
device_name on directory type filesystem_type (options)
To display only a certain file systems use the
For example to display only the ext4 partitions you would use:
mount -t ext4
Mounting a File System
To attach a file system at a specified location (mount point), use the
mount command in the following form:
mount [OPTION...] DEVICE_NAME DIRECTORY
Once the file system is attached, the mount point becomes the root directory of the mounted file system.
For example to mount the
/dev/sdb1 file system to the
/mnt/media directory you would use:
sudo mount /dev/sdb1 /mnt/media
Usually when mounting a device with a common file system such as ext4 or xfs the
mount command will auto-detect the file system type. However, there are some file systems that are not recognized, and need to be explicitly specified.
-t option to specify the file system type:
mount -t TYPE DEVICE_NAME DIRECTORY
To specify additional mount options, use the
mount -o OPTIONS DEVICE_NAME DIRECTORY
Multiple options can be provided as a comma separated list (do not insert a space after a comma).
You can get a list of all mount options by typing
man mount in your terminal.
Mounting a File System using /etc/fstab
When providing just one parameter (either directory or device) to the
mount command, it will read the content of the
/etc/fstab configuration file to check if the specified file system is listed.
/etc/fstab contains information about the given file system, the
mount command will fill in the value for the other parameter and use the mount options specified in the fstab file.
/etc/fstab file contains a list of entries in the following form:
[File System] [Mount Point] [File System Type] [Options] [Dump] [Pass]
mount command in one of the following forms to attach a file system specified in the
mount [OPTION...] DIRECTORY mount [OPTION...] DEVICE_NAME
Mounting USB Drive
On most modern Linux distribution like Ubuntu USB drive will auto mount when you insert it, but sometimes you may need to manually mount the drive.
To manually mount an USB device use the following steps:
Create the mount point:
sudo mkdir -p /media/usb
Assuming that the USB drive uses the
/dev/sdd1device you can mount it to
/media/usbdirectory by typing:
sudo mount /dev/sdd1 /media/usb
To find the device and filesystem type you can use any of the following commands:
fdisk -l ls -l /dev/disk/by-id/usb* dmesg lsblk
Mounting ISO Files
To mount an ISO file use the loop device. The loop device is a special pseudo-device that makes a file accessible as a block device.
Start by creating the mount point, it can be any location you want:
sudo mkdir /media/iso
Mount the ISO file to the mount point by typing the following command:
sudo mount /path/to/image.iso /mnt/iso -o loop
Don’t forget to replace
/path/to/image.isowith the path to your ISO file.
To mount a NFS system you’ll need to have the NFS client package installed on your system.
Install NFS client on Ubuntu and Debian:
sudo apt install nfs-common
Install NFS client on CentOS and Fedora:
sudo yum install nfs-utils
Use the steps below to mount a remote NFS directory on your system:
Create a directory to serve as the mount point for the remote filesystem:
sudo mkdir /media/nfs
Generally, you will want to mount the remote NFS directory automatically at boot. To do so open the
/etc/fstabfile with your text editor:
sudo nano /etc/fstab
Add the following line to the file, replacing
remote.server:/dirwith the NFS server IP address or hostname and the exported directory:/etc/fstab
# <file system> <dir> <type> <options> <dump> <pass> remote.server:/dir /media/nfs nfs defaults 0 0
Mount the NFS share by running the following command:
sudo mount /mnt/nfs
Unmounting a File System
To detach a mounted file system, use the
umount command followed by either the directory where it has been mounted (mount point) or the device name:
umount DIRECTORY umount DEVICE_NAME
If the file system is in use the
umount command will fail to detach the file system. In those situations, you can use the
fuser command to find out which processes are accessing the file system:
fuser -m DIRECTORY
Once you determine the processes you can stop them and unmount the the file system.
--lazy) option to deatach a busy file system as soon as it is not busy anymore.
umount -l DIRECTORY
--force) option to force an unmount. This option is usually used to unmount an unreachable NFS system.
umount -f DIRECTORY
Generally not a good idea to force unmount as it may corrupt the data on the file system.
By now you should have a good understanding of how to use the
mount command to attach various file systems to your directory tree and detaching the mounts with the
To learn more about the
umount command options see their respective man pages.