HOW TO MOUNT & UNMOUNT DRIVES AND DISKS IN LINUX
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.
To list all the available devices that are currently mounted.
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.
Here we have created a directory partition which acts as a mount point for /dev/sda2
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.
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,
/dev/sda2 /partition ext4 defaults 0 0
The above line explains that the partition /dev/sda2 will be mounted permanently under /partition directory.
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.
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.
#mount -t nfs 192.168.10.10:/nfsshare /share
The above command will mount the /nfsshare directory in our local machine’s /share directory and 192.168.10.10 is the NFS server.
In order to mount the NFS shared directory permanently on your machine, We need to add an entry in /etc/fstab.
192.168.10.10:/nfsshare /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