YouTube Icon

Code Playground.

How to Mount and Unmount File Systems in Linux

CFG

How to Mount and Unmount File Systems in Linux

On Linux and UNIX working frameworks, you can utilize the mount order to append (mount) document frameworks and removable gadgets, for example, USB streak drives at a specific mount point in the index tree. 

The umount order withdraws (unmounts) the mounted document framework from the catalog tree. 

In this instructional exercise, we will go over the nuts and bolts of appending and separating different document frameworks utilizing the mount and umount orders. 

How to List Mounted File Systems

At the point when utilized with no contention, the mount order will show all at present appended document frameworks: 

mount

Of course, the yield will incorporate all record frameworks including the virtual ones, for example, cgroup, sysfs, and others. Each line contains data about the gadget name, the catalog to which the gadget is mounted to, the kind of the filesystem and the mount choices in the accompanying structure: 

device_name on directory type filesystem_type (options)

To show just certain document frameworks utilize the - t alternative. 

For instance, to print just the ext4 segments you would utilize: 

mount -t ext4

Mounting a File System

To mount a record framework in a given area (mount point), utilize the mount order in the accompanying structure: 

mount [OPTION...] DEVICE_NAME DIRECTORY

When the record framework is appended, the mount point turns into the root index of the mounted document framework. 

For instance, to mount the/dev/sdb1 document framework to the/mnt/media registry you would utilize: 

sudo mount /dev/sdb1 /mnt/media

Normally when mounting a gadget with a typical record framework, for example, ext4 or xfs the mount order will auto-identify the document framework type. Notwithstanding, some record frameworks are not perceived and should be expressly determined. 

Utilize the - t alternative to indicate the document framework type: 

mount -t TYPE DEVICE_NAME DIRECTORY

To indicate extra mount alternatives , utilize the - o choice: 

mount -o OPTIONS DEVICE_NAME DIRECTORY

Different alternatives can be given as a comma-isolated rundown (don't embed a space after a comma). 

You can get a rundown of all mount alternatives by composing man mount in your terminal. 

Mounting a File System utilizing/and so on/fstab 

While giving only one boundary (either registry or gadget) to the mount order, it will peruse the substance of the/and so forth/fstab arrangement document to check if the predefined record framework is recorded. 

In the event that the/and so forth/fstab contains data about the given document framework, the mount order utilizes the incentive for the other boundary and the mount alternatives determined in the fstab record. 

The/and so on/fstab document contains a rundown of sections in the accompanying structure: 

/etc/fstab

[File System] [Mount Point] [File System Type] [Options] [Dump] [Pass]

Utilize the mount order in one of the accompanying structures to append a document framework determined in the/and so on/fstab record: 


mount [OPTION...] DIRECTORY
mount [OPTION...] DEVICE_NAME

Mounting USB Drive

On most present day Linux dispersion like Ubuntu, USB drives will auto mount when you embed it, however now and then you may have to physically mount the drive. 

To physically mount a USB gadget, play out the accompanying advances: 

Make the mount point: 

sudo mkdir -p /media/usb

Expecting that the USB drive utilizes the/dev/sdd1 gadget you can mount it to/media/usb registry by composing: 

sudo mount /dev/sdd1 /media/usb

To discover the gadget and filesystem type, you can utilize any of the accompanying orders: 

fdisk -l
ls -l /dev/disk/by-id/usb*
dmesg
lsblk

To mount exFAT organized USB drives, introduce the free FUSE exFAT module and apparatuses . 

Mounting ISO Files

You can mount an ISO record utilizing the circle gadget which is an exceptional pseudo-gadget that makes a document available as a square gadget. 

Start by making the mount point, it tends to be any area you need: 

sudo mkdir /media/iso

Mount the ISO document to the mount point by composing the accompanying order: 

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

Remember to supplant/way/to/image.iso with the way to your ISO document. 

Mounting NFS 

To mount a NFS share you'll have to have the NFS customer bundle introduced on your framework. 

Introduce NFS customer on Ubuntu and Debian: 

?
sudo mount /path/to/image.iso /media/iso -o loop

?

Introduce NFS customer on CentOS and Fedora: 

sudo yum install nfs-utils

Utilize the means beneath to mount a distant NFS registry on your framework: 

Make an index to fill in as the mount point for the far off filesystem: 

sudo mkdir /media/nfs

For the most part, you will need to mount the far off NFS share consequently at boot. To do so open the/and so on/fstab record with your content manager : 

sudo nano /etc/fstab

Add the accompanying line to the document, supplanting remote.server:/dir with the NFS worker IP address or hostname and the traded index: 

/etc/fstab

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

Mount the NFS share by running the accompanying order: 

sudo mount /media/nfs

Unmounting a File System

To isolate a mounted record framework, utilize the umount order followed by either the index where it has been mounted (mount point) or the gadget name: 


umount DIRECTORY
umount DEVICE_NAME

On the off chance that the document framework is being used the umount order will neglect to isolate the record framework. In those circumstances, you can utilize the fuser order to discover which cycles are getting to the record framework: 

fuser -m DIRECTORY

When you decide the cycles you can stop them and unmount the document framework. 

Lazy unmount

Utilize the - l (- - apathetic) alternative to unmount a bustling record framework when it isn't occupied any longer. 

umount -l DIRECTORY

Force unmount

Utilize the - f (- - power) choice to compel an unmount. This choice is normally used to unmount an inaccessible NFS framework. 

umount -f DIRECTORY

By and large not a smart thought to drive unmount as it might degenerate the information on the document framework. 

Conclusion

At this point you ought to have a decent comprehension of how to utilize the mount order to connect different document frameworks to your registry tree and separating the mounts with the umount order. 

To become familiar with the mount and umount order choices see their separate man pages.




CFG