How To Mount And Unmount File Systems From The Linux Terminal?

How To Mount And Unmount File Systems From The Linux Terminal?

   

This post was last updated on July 1st, 2020 at 10:24 am

In Linux or Unix, mount command is used to mount(attach) a filesystem or storage device to a specific directory in the directory tree. The directory to which it is mounted is known as the mount point for the filesystem.

The umount command is used to safely unmount(detach) a mounted filesystem from the directory tree.

In this article, we will discuss to mount or unmount a mounted filesystem in Linux by using the terminal.

List the mounted filesystems using the mount command

You can list the mounted filesystems by using mount command without any option. It displays the information of all filesystem including virtual ones such cgroup, sysfs, etc. Now use the following command –

mount

You can refine the output of mount command by using the option -t.

For example –

mount -t ext4

Mount a filesystem

To mount a filesystem in the existing directory structure we will use the mount command. The syntax of mount command is given below –

mount [options] filesystem_or_device_name directory

For example –

To mount /dev/sdb1 filesystem to /mnt/media directory we use –

mount /dev/sdb1 /mnt/media

Usually, when you mount a device with a common filesystem such as ext4, it detects filesystem type automatically. If not detected you can explicitly mention the filesystem by using the option -t.

How to mount an ISO file

You can mount an iso file to a specific directory so that it’s content available as the part of existing filesystem. I have Ubuntu 20.04 LTS iso in my system I will mount it to /mnt directory. To mount iso use the following command –

sudo mount -t iso9660 -o loop ubuntu-20.04-desktop-amd64.iso /mnt

Now you can access the content by navigating to /mnt directory.

How to mount the USB drive

In most of the distributions, a USB drive is automatically get mounted when you insert it in a USB port. If not mounted automatically you can manually mount it. When you manually mount a USB drive you can mount it to a specific directory.

Suppose we have USB /dev/sdb1 and want to mount it on /media/usbdrive. First, create the directory usbdrive inside media directory by using the following command-

mkdir -p /media/usbdrive

Now use the following command to mount /dev/sdb1 to /media/usbdrive

sudo mount /dev/sdb1 /media/usbdrive

Unmount a filesystem

To unmount a filesystem or storage device umount command is used. Following is the syntax of umount command –

umount directory_or_device

If a filesystem is in use umount command will fail to unmount. You can use the fuser command to see which process is accessing the filesystem.

fuser -m directory_or_device

Once you identify the process you can stop it and unmount the filesystem.

Lazy unmount

The --lazy or -l option can be used to unmount a busy filesystem safely. This option causes the umount to wait until the filesystem is able to be safely unmounted. Run the following command if you want to use lazy unmount-

umount -l filesystem_or_device

Force unmount

You can use -f or --force option to forcefully unmount a filesystem. Use the command as given below to force unmount a filesystem.

umount -f filesystem_or_device

Conclusion

Now I hope you got a basic understanding of how to mount or unmount a filesystem in Linux or Unix. If you want to say something on this topic then write to us in the comments below.

Previous How To Change User's Password Through Terminal In Linux/Unix?
Next [lubuntu] Trying to figure out how to make network work permanently

About author

You might also like

Uncategorized 0 Comments

How To Setup FTP Server In Ubuntu 20.04 LTS?

FTP or File Transfer Protocol is a standard networking protocol used to transfer files between client and server. An FTP user may authenticate themselves by using username and a password.

Uncategorized 1Comments

How To Change Bootscreen Logo In Linux Mint?

This post was last updated on June 27th, 2020 at 12:55 pmContents1 Bootscreen2 Plymouth3 Steps to change the logo in Linux mint-4 Conclusion Bootscreen A bootscreen is a graphical representation

Uncategorized 0 Comments

How To Find UID And GID Using Id Command In Linux/Unix?

Linux/Unix are multi-user operating systems that means different users can access and use system resources simultaneously. To access the resources of a system you must have a user account on

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply