In Linux and Unix based operating system if you want to connect or attach some kind of storage device then we called it mount.
The mount command helps you to connect with your system for eg. If you want to connect USB flash drives or pen drive to mount at the specific directory.
The umount commands work is to detaches from the mounted file system from your Operating system.
So, We will cover how to list all mounted file systems, how to unmount files from the system with the examples.
Table of Contents
How to Check all mount File System in Linux?
You are wondering how you can check which file is already mounted to the system there are many ways, which I used and I prefer using lsblk instead of on the mount, ls -l /dev/disk/by-id/usb*, dmesg.
For better understanding, I” give you examples of both lsblk and mount command.
A command lsblk uses the list down all the mounted and unmounted file systems in a tree structure. This command will also give you the complete details of Partitions, Partition Size, Size of Disk, where it is the mount, and as you mount the file it shows under the mount point.
Now we will check what mount command will show on Terminals
When you pass mount command to terminal output will show you all the file systems like cgroup,sysfs and others.
The output consists of the device name, the directory where the file is mounted, what type of file it is, and the last mount options. To understand more precisely I’ll make dummy syntax
deviceName on directory typeOfFile (options)
I’ll show you one examples so you will get the better idea.
mount -t ext4
Mounting a File System
We will show you how you can mount a file system in a specific given location. Once the file system
mount [OPTIONS] DEVICE NAME DIRECTORY
If you want to mount /sda2 partition to the system then pass command like this.
sudo mount /dev/sda1 /mnt/media
Make sure to provide the type of file format else it will show an error on the screen. In common file systems like ext4 or xfs format auto-detect by the systems.
I’ll show you an example of how you can use the type command, In this case, my USB drive format is “msdos“.
sudo mount -t msdos /dev/sdb1 /media/shen/USB/
After mount, you have to type parameter -t and the file format name rest syntax will be the same.
Mounting USB Drive
You want to know how to mount to USB Drive in you Linux system through terminal just follow the step,By Default Linux will mount the USB Drive So,First we have to unmount USB drive from system.
To unmount USB Drive
sudo umount /deviceName / directoryPath
sudo umount /dev/sdb1 /media/shen/SMBB
After umount remount using terminal,first create mount point.
sudo mkdir -p /media/USB_DRIVE
sudo mount /dev/sdb1 /media/USB_DRIVE
That’s it now you can use USB drive.
Unmounting File System
Now you know how to mount, we will see how to umount or detach a mount file system. To detach we use command umount.
sudo umount [directory] or sudo umount [device_name]
I’ll explain this syntax with example
sudo umount /dev/sdb1
You can use lazy option to detach from the running process.This option will detach mounted device as soon as process get stopped.
$ umount -l [directoryName]
You can check mounted device on the system through various way like fdisk -l, ls -l /dev/disk/by-id, lsblk.
To mount use command mount and to detach umount. You can learn more about the option and usage of the mount by reading the manual page
A man with a tech effusive, who has explored some of the amazing technology stuff and exploring more, While moving towards, I had a chance to work on Android Development, Linux, AWS, DevOps with several Open source tools.
One of my life mottos “Always be lifelong Students.”