• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Mount and Unmount File Systems in Linux

Written by Admin, Updated On May 31, 2020
mount, terminal, umount
How to Mount and Unmount File Systems in Linux

The mount command mounts (attach) file systems or a storage device and makes it accessible in the existing directory tree. While the umount command detaches the mounted file system from the directory structure. In this tutorial, you will learn how to attach and detach file systems using the mount and umount commands.

List Mounted File Systems#

To list the all currently attached file systems, run mount command without any argument:

mount

This will show information about the device name, directory path where the device is mounted, filesystem type and mount option.

Mounting a File System#

Use the mount command as following to mount a file system for a specific location:

mount [OPTION...] DEVICE_NAME DIRECTORY

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

For instance, to mount the /dev/sdb2 file system to the /mnt/tns directory you would use:

sudo mount /dev/sdb2 /mnt/tns

Generally, when mounting a device it will auto-detect the file system type. However, some file systems are not recognized and need to be explicitly specified.

You can use -t option to specify the file system type:

mount -t TYPE DEVICE_NAME DIRECTORY

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

mount -o OPTIONS DEVICE_NAME DIRECTORY

Get a list of all mount options by typing man mount in your terminal.

Mounting USB Drive#

Most latest Linux distro like Ubuntu, it will mounts USB drives automatically when you insert it, but sometimes you may need to manually mount the drive.

Perform the following steps, to manually mount a USB device:

At first, create the mount point by typing:

sudo mkdir -p /media/usb

For example, your USB drive uses /dev/sdd2 device, run following command to mount it to /media/usb directory:

sudo mount /dev/sdd2 /media/usb

Use the below command to find the device and filesystem type:

fdisk -l

Mounting ISO Files#

Perform the following steps to mount an ISO file.

Make a mounting point and location would be as per your choice:

sudo mkdir /media/iso

Now mount the ISO file to the mount point by typing:

sudo mount /home/filename.iso /media/iso -o loop

You should replace /home/filename.iso with your ISO file path.

Mounting NFS#

It’s required to have NFS client package installed on your system, before going to mount an NFS share.

Install NFS client on Ubuntu and Debian:

sudo apt install nfs-common

Install NFS client on CentOS and Fedora:

sudo yum install nfs-utils

Now follow the given steps to mount a remote NFS directory on your system:

Create a directory for mount point for the remote filesystem:

sudo mkdir /media/nfs

To mount the remote NFS share automatically at boot, edit the /etc/fstab file with your text editor:

sudo nano /etc/fstab

Add the following lines to the file and you should replace remote.server:/dir with the NFS server IP address and the exported directory:

# <file system>    <dir>       <type>   <options>   <dump>	<pass>
remote.server:/dir /media/nfs  nfs      defaults    0       0

Run following command to mount the NFS share:

sudo mount /media/nfs

Unmounting a File System#

You can use the umount command to detach a mounted a file system. Use the umount command in following form:

umount DIRECTORY
umount DEVICE_NAME

Sometimes, the umount command will fail to detach the file system. So use the fuser command to find out which processes are accessing the file system:

fuser -m DIRECTORY

After determining the processes you can stop them and unmount the file system.

To unmount a busy file system use the -l (--lazy) option as following:

umount -l DIRECTORY

You can unmount using -f (--force) option to force an unmount. This option is usually used to unmount an unreachable NFS system.

umount -f DIRECTORY

Force mount may corrupt the data on the file system so it’s not recommended.

Conclusion#

Hopefully, you successfully learned about how to use mount and umount command to attach and detach various file systems to your directory structure.

If you have any question or feedback, leave a comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Install Xrdp Server (Remote Desktop) on Debian 10
Next Article   How to Install Docker Compose on Ubuntu 20.04

Related Posts

  • How to Install SSH Keys on Ubuntu 22.04

    How to Set up SSH Keys on Ubuntu 22.04

    January 7, 2023
  • How to Install Fail2ban on Ubuntu 22.04

    How to Install and Configure Fail2ban on Ubuntu 22.04

    December 5, 2022
  • How to Enable SSH on Ubuntu 22.04

    How to Enable SSH on Ubuntu 22.04

    December 1, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install Microsoft Edge Browser on Ubuntu 22.04
    How to Install Microsoft Edge Browser on Ubuntu 22.04 March 14, 2023
  • How to Install Ruby on Ubuntu 22.04 LTS
    How to Install Ruby on Ubuntu 22.04 LTS February 27, 2023
  • How to Install LEMP Stack on Ubuntu 22.04
    How to Install LEMP Stack on Ubuntu 22.04 March 18, 2023
  • How to Install Set Up Apache Virtual Hosts on Ubuntu 22.04
    How to Set Up Apache Virtual Hosts on Ubuntu 22.04 March 2, 2023
  • How to Install MariaDB on Debian 11 Bullseye
    How to Install MariaDB on Debian 11 Bullseye March 8, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook