In this tutorial, We are going to learn how to mount drivers and partitions in Linux systems in the command line.

We can mount a new partitions or devices by creating a new directory or on existing directory which is empty.

Mount Commands

To list all the available devices that are currently mounted.






Mounting Partitions

In order to mount a new partition, For example, We have a new partition /dev/sda2 with an ext3/ext4 filesystem, First We need to create a mount point.

#mkdir /partition

Here we have created a directory partition which acts as a mount point for /dev/sda2

Temporary Mount

Now, We need to mount the disk into the directory.

#mount /dev/sda2  /partition

Mount command will automatically detects the filesystem of a partition, We can mention in some cases If required.

#mount /dev/sda2  -t ext4   /partition

But, We have performed a temporary partition as when the system reboots the partition will become unmounted.

Permanent Mounting

To make a partition to mount permanently, We need to make an entry for the partition in /etc/fstab.

Open the file and add the entry as shown below,

#vi /etc/fstab

/dev/sda2     /partition       ext4     defaults         0           0

The above line explains that the partition /dev/sda2 will be mounted permanently under /partition directory.

Unmount Partitions

umount is the command used for unmounting the partitions and devices on the Linux systems.

We can use either of the below commands to unmount the partition either by the mount point or the block device.

#umount   /dev/sda2

#umount   /partition

Mounting NFS Shares

NFS share is the directory in the remote server which will be mounted in the Local server.

Here, We are going to mount the directory which is shared from NFS server on our local machine.

Temporary Mount

#mount -t  nfs     /share

The above command will mount the /nfsshare directory in our local machine’s /share directory and is the NFS server.

Permanent Mount

In order to mount the NFS shared directory permanently on your machine, We need to add an entry in /etc/fstab.     /share     nfs   defaults    0    0

We have mounted /nfsshare directory permanently under /share folder on our local machine.

Mounting ISO File

To mount .iso file to the linux system, Use the below command.

#mount -t iso9660 -o loop linuxcloudops.iso /mnt

Here We are mounting linuxcloudops.iso iso file into /mnt directory.

iso9660 is the filesystem of the iso file.

loop make the devices to be accessed as a block device.

For Permanent Mount

To permanently mount, Make an entry in /etc/fstab.

linuxcloudops.iso   /mnt     iso9660     defaults    0   0

If you want to activate all the mounted partitions immediately, Use mount -a to update /etc/fstab.

That’s All.Thanks for reading this article.Hope you find it helpful.