Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Mount and Unmount File Systems in Linux - DesignLinux

May 31 2020
designlinux 0 Comments
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.

Related

Tags: mount, terminal, umount

Bash printf Command

Prev Post

How to Install Xrdp Server (Remote Desktop) on Debian 10

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 259
  • 614,631

DesignLinux.com © All rights reserved

Go to mobile version