Home » Linux: Mount and Unmount File System on Linux

Linux: Mount and Unmount File System on Linux

by Pring
Linux: Mount and Unmount File System on Linux

I. Introduction.

This tutorial will teaches you how to Mount and Unmount file system in Linux. On Linux and Unix operating systems, you can use the mount command to attach (mount) file systems from the directory tree.
The umount command to detached (umount) the mounted file systems from the directory tree.

The mount command mounts a storage device or filesystem, making it accessible and attaching it to an existing directory structure.

The umount command “unmounts” a mounted filesystem, informing the system to complete any pending read or write operations, and safely detaching it.

II. Prerequisites.

1. Login to your system via SSH. You can use PuTTy tool or Poderosa tool,…
2. Login with root user.  If you are logged in as another user, you will need to add sudo before each command.

III. How to Mount and Unmount File System on Linux in simple steps.

The article includes the following categories:

Step 1. How to List Mounted File Systems.
Step 2. Mount File System.
Step 3. Mount NFS.
Step 4. Mount IOS files.
Step 5. Unmount File System.

You can see details of Video on How to Mount and Umount File Systems on Linux – CentOS 7 as below.
[Sorry, the video we will update later]

You also can see details as below.

Step 1. How to List Mounted File Systems.

The mount command will display all currently attached file systems:
On terminal enter the command below.

mount

Sample Output:

[root@devopsio ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
...

Or you also using following command to check.

df -h

Sample Output:

[root@devopsio ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda         25G  5.5G   18G  25% /
devtmpfs        486M     0  486M   0% /dev
tmpfs           496M     0  496M   0% /dev/shm
...

Step 2. Mount File Systems.

The command pattern below:

sudo mount [Source NFS Dir] [Target Dir]

So, Enter the command below:

sudo mount /dev/sda1 /mnt_nfs/xxx_vol

Step 3. Mount NFS.

1. First, you`ll need to have the NFS client package installed on your system.

Install NFS client on CentOS and Fedora.
Enter the command below.

sudo yum install nfs-utils

Install NFS client on Ubuntu and Debian.
Enter the command below.

sudo apt install nfs-common

2. Mount a remote NFS directory on your system.

– The Mount Point directory: /mnt_nfs/xxx
– NFS directory: ip_address:/mnt_nfs/xxx_vol

Have 2 ways to mount.
Option 1: Mount by manually.
Enter the command below.

sudo mount ip_address:/mnt_nfs/xxx_vol /mnt_nfs/xxx

Option 2: Auto mount when reboot your system.
Creating the mount point, it can be any location you want.
Enter the command below.

sudo mkdir /mnt_nfs/xxx

Configure to mount the remote NFS directory automatically at boot.
Enter the command below.

sudo vi /etc/fstab

Paste content as below:

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

Explain: [ /mnt_nfs/xxx ] is the mount point, target directory.

The command pattern below.

sudo mount ip_address:/mnt_nfs/xxx_vol

Explain: [ /mnt_nfs/xxx ] is the NFS directory.

Step 4. Mount IOS files.

We also mount an ISO file. First, Creating the mount point, it can be any location you want.
Enter the command below.

sudo mkdir /tmp/iso

Mount the ISO file to the mount point. Enter the command below.

sudo mount /path/to/image.iso /tmp/iso -o loop

Step 5. Umount File System.

To detach a mounted file system. Enter the command pattern below.

sudo umount DIRECTORY
sudo umount DEVICE_NAME

In the case file system is in use the umount command will fail to detach the file system.
In those situations, you can find out which processes are accessing the file system.
Enter the command below.

fuser -m DIRECTORY

Once you determine the processes, you can stop them with 2 following ways.

1. Lazy unmount.

This is the option to unmount a busy file system as soon as it is not busy anymore.
The command pattern below.

sudo umount -l DIRECTORY

Explain: -l : –lazy

2. Force unmount.

This options is usually used to unmount an unreachable NFS system.
The command pattern below.

sudo umount -f DIRECTORY

Explain: -f : -force

But in the case, it is working, enter the command pattern below.

sudo umount -lf DIRECTORY

IV. Conclusion.

In this tutorial, we was How to Mount and Unmount File System on Linux. If you hit a problem or have feedback, leave a comment below.


How to Mount and Unmount File System on Linux is complete. Wish you success and luck.
Thanks and best regards!
— Pring —

Related Articles

7 comments

vurtil opmer November 27, 2019 - 2:35 pm

I couldn’t resist commenting

Reply
alcohol rehab nea rme February 27, 2020 - 4:52 pm

I pay a quick visit each day some web pages and blogs to read posts, but this blog provides quality based content.

Reply
Alan Chester April 9, 2020 - 1:05 am

Hello,

My name is Alan and I’d like to pay you money via paypal to post content on your website. How much would you charge for something like that? The content can be written to fit your website.

Alan

Reply
lô đề online October 27, 2020 - 12:17 am

We are a group of volunteers and opening a new scheme in our community.
Your website provided us with valuable info to work on. You’ve done
a formidable job and our entire community will be thankful to you.

Reply
joker December 10, 2020 - 4:04 pm

Howdy! This is kind of off topic but I need some guidance from an established blog. Elna Rolando Arlie

Reply
hd sex December 14, 2020 - 7:18 pm

What a material of un-ambiguity and preserveness of precious knowledge concerning unexpected feelings. Eleni Morie Oby

Reply
porno December 14, 2020 - 8:29 pm

Great post. I am going through a few of these issues as well.. Avril Joseph Schinica

Reply

Leave a Comment