How to Mount and Unmount Linux File System
In this article we are going to learn How to mount and unmount Linux file system. In Linux operating system after create a fresh partition we have to format that partition with some file system eg: ext2, ext3, ext4 and so on and then Mount that file system (Partition) on a directory to use that partition and to store data on that partition.
There are two types of file system mounting we have in Linux. one is Temporary mounting & other one is Permanent mounting. Here I am going to explain both type of mounting in this article. So let’s get started.
Here I have a partition i.e /dev/sdb1 which I am going to mount on a directory.
[email protected]:~$ sudo fdisk -l | grep /dev/sdb1 /dev/sdb1 2048 8390655 8388608 4G 83 Linux
Mount a File System (Partition) [Temporary Mounting]
What is Temporary Mounting of File System ?
Ans : Temporary mounting of file system is something that will unmount automatically after reboot the system.
So to mount a file system (Partition) we need a directory. So first create a directory using below command. Here I am going to create a directory named mydata.
[email protected]:~$ mkdir mydata # Create a Directory
My partition is formatted with ext3 file system and ready for mounting. So let’s mount the file system using mount command. Refer the below command.
[email protected]:~$ sudo mount /dev/sdb1 mydata/ # Mount a File System
We have successfully mounted the file system using mount command. To confirm the same you can use the df -h command. Refer the command below.
[email protected]:~$ df -h | grep mydata # Confirm the mounted file system /dev/sdb1 3.9G 8.2M 3.7G 1% /home/itsmarttricks/mydata
OR you can also use mount command to check mounted file system. Refer the command below.
[email protected]:~$ mount | grep /dev/sdb1 # Confirm the mounted file system /dev/sdb1 on /home/itsmarttricks/mydata type ext3 (rw,relatime,data=ordered)
Unmount Linux File System
To unmount the file system use the below command.
[email protected]:~$ sudo umount mydata/ # Unmount the File System
Above I explained How to do temporary mounting of a file system. Now to mount the file system permanently you have to edit a file called /etc/fstab. So edit the file using below command.
[email protected]:~$ sudo nano /etc/fstab # Edit the /etc/fstab file
After edit the file add the below line in to that file and save it.
/dev/sdb1 /home/itsmarttricks/mydata ext3 defaults 0 0
Explanation of above line :
- /dev/sdb1 : Partition Name
- /home/itsmarttricks/mydata : Mount Directory
- ext3 : File System
- defaults : Permission
- 0 : For dump Backup
- 0 : For FSCK check
To Unmount Permanent File System just edit the /etc/fstab file and remove the line which we added on above step. Then to refresh the file system table run the below command.
[email protected]:~$ mount -a # Refresh the File System Table
Also Read – Complete Unix Commands And Basic Linux Commands With Examples For Beginners
That’s all, In this article, we have explained How to mount and unmount Linux file system. I hope you enjoy this article. If you like this article, then just share it. If you have any questions about this article, please comment.