Mounting Disk in Linux using fstab Option
What is Mounting Disk in Linux
Mounting disk in Linux is actually a process to access a partitioned and formatted hard disk in the system. Whatever data is stored in a hard disk can only be accessed or used after mounting that hard disk in Linux Operating System. As we know when a pen drive is inserted in the USB slot of Windows system, the pen drive will automatically be available for access in the windows home folder. This is only due to “plug and play” options installed in Windows operating system. But, in Linux, inserting or connecting a hard disk in the system, is not enough to access that disk. Before accessing it, the hard disk has to partitioned, formatted followed by mounting it in the system. However, the hard disk can be mounted with any of the single or multiple folder of Linux system. There is no restriction of mounting location of that hard disk. The following diagram is explained the basic difference between inserting a hard disk in Linux and Windows operating system.
Requirement before Mounting Disk in Linux
A new hard disk can not be used with Linux system directly. Before using it, the following have to be ensured :-
- Partitioning of the hard disk with use of “fdisk” command
- Formatting the hard disk with use of command “mkfs“. Formatting is basically process of configuring the file system of the disk. There are many kinds of file system for Linux system is available :-
To understand the procedure of partitioning and formatting of a hard disk, you can follow the blog “Fdisk command to create and delete partition in Linux“.
Use of fstab Option
What is fstab Option
Mounting a disk in any folder is being done by command “mount“, but such mounting is not permanent in nature. The mounted disk will automatically be unmounted after shutting down the system. When the system will reboot, the mounted disk will be disappeared. The disk must again be mounted for use or access. To avoid such process of mounting a disk again and again with every system boot, we have to mount the disk permanently. To make stable the mounting, fstab option should be used with some statement entry in “fstab” file is required. This “fstab” file is kept in /etc directory by default. Full form of “fstab” can be elaborated to understand as “File System Table”. In this file, a table of instructions for each permanently mounted hard disk is being maintained. If we read the file “fstab“, a table will be shown with some entry. The following diagram will be explained the line of instructions of this file :-
There will be six columns in the table of “fstab” file. Each column require specific entry related to the mounted disk.
First Column of fstab Option
The disk device will be denoted in this column with its name-id with absolute path or UUID (universal Unique ID). The default location of each and every hard disk will be “/dev“
Name-id of a all the Hard Disk of a System
Description : The name-id including its all particulars like absolute path, size, sectors, partitioning profile etc of each hard disk will be displayed. The hard disk will be displayed as sda, sdb, sdc … and so on. Generally, sda will be the system hard disk in which Linux OS is installed. On adding a new hard disk in the system, the same will be named as “sdb“. Accordingly, adding of more hard disk will be shown as “sdc“, “sdb“… etc.
Name-id of a Particular Hard Disk of a System
fdisk -l /dev/sdc
Description : Particulars of hard disk “sdc” will be displayed with its all available partitioned profile. The partitioned portion of the hard disk will be named serially as “sdc1“, “sdc2“, “sdc3” and onward in a table. In Cent_OS 8, the size of partitioned portion will also be displayed before ID column of the table.
Name-id of a Particular Hard Disk of a System in Short
fdisk -l | grep /dev/sdc
Description : Very short particulars of the hard disk will be displayed. Even table heading will not be shown.
View Size of Hard Disk with its Partition
Description : A table of all the available hard disk tree with its partitions including name-id and size will be displayed.
UUID and File System of a Hard Disk
Description : UUID of all the hard disk with its name-id including File system information will be displayed.
Second Column of fstab Option
This column is specified to denote the location of the mounted disk with absolute path. As we know, hard disk can be mounted any of the folder or sub folder of the system, the location with absolute path must be mentioned here during editing of “fstab” file. For mounting a hard disk in a system in multiple folders, the entry should be made separately for each folder. If the hard disk has mounted in “c1data” of “zivi” folder under “home” directory, then the path should be mentioned as “/home/zivi/c1data“.
Third Column of fstab Option
This column is specified to denote file system of disk. File system, which has configured during formatting of the disk, can be seen with use of command “blkid“, already explained above under heading “UUID and File System of a Hard Disk”
Fourth Column of fstab Option
This column is specified to denote various mount option including permissions etc. Generally, this is set as “default” by the system for normal user or normal use of disk. The mount option may be changed according to user requirement when a specific disk to be mounted for a specific type of job. Multiple mount options can also be used separated by commas.
Fifth Column of fstab Option
This column is specified to denote willingness to get dump backup of the partition. The value zero (0) denotes “no backup” and the value one (1) denotes “dump backup” of the partition. However, this column may be left blank if, no backup option is required.
Sixth Column of fstab Option
This column is specified to denote file system check priority for fs checks regarding errors of partition at the time of system boot. File system check at the time system boot is good idea to keep disk update all time, but this process will be time consuming. It will take much time to ready a system for use after booting. Therefore, generally, the fs checks order set to zero (0) for no checking. However, priority for checking of disk can be set in order of numerical numbers such as 1, 2, 3 ….. onward.
Mounting Disk in Linux
Mounting a Hard Disk Partition in Linux
mount /dev/sdc1 /home/zivi/c1data
Description : On listing of folder c1data under /home/zivi/, no file or folder found. After mounting the partition sdc1 in the folder c1data under /home/zivi/, a folder “profile” found in the folder “c1data“. Hence, the folder “profile” kept in hard disk “sdc1“. After re-boot the disk sdc1 will automatically be unmounted.
Mounting a CD ROM in Linux
mount /dev/cdrom /mnt/mycd
Description : A cdrom device mounted in “mycd” folder of “mnt” directory.
Mounting an ISO image in Linux
mount -o loop centos8.iso /mnt/cos8
Description : the iso image file “centols8.iso” mounted in the folder “cos8” in the directory “mnt”
Description : After un-mounting the disk from “c1data” folder, the folder “profile” removed.
Mounting a Hard Disk Permanently in Linux
Mount a Hard Disk in Linux
Firstly, create a mounting mount in the folder “mnt” as “hdc1“. Then, use following command to mount the disk “sdc1” into the folder “hdc1” of “mnt” folder.
mount /dev/sdc1 /mnt/hdc1
Description : The disk sdc1 mounted in the folder “hdc1” of “mnt” directory temporarily.
Use of fstab Option
Read fstab file kept in /etc Directory
Description : Check the list of disk and device already entered in the file “fstab” and ensure the value of new device is not already entered in the table of “fstab” file.
Edit fstab file Kept in /etc Directory with vi Editor
Press “I” to insert/edit value in the file “fstab“. Make entry in last row of the table regarding value of “sdc1” disk as under
/dev/sdc1 /mnt/hdc1 ext4 default 0 0
In the above row, you can enter UUID of the disk in place of name id i.e., “/dev/sdc1“. You can find UUID of the disk by using command “blkid“.
Press “Esc” button to quit edit option and entering command option. Then just press ” :wq” to save and quite the “vi” editor.
Press Enter button to quit from “vi” editor.
Now the entry of “sdc1” disk has been made in the file “fstab” in /etc and the said disk has permanently mounted in the system. After re-booting, the disk will not unmounted automatically as usual.
You can also visit at the following links to read more on Linux :-
- Use of cp Command to Copy a File in Linux
- Make Directory using mkdir Command in Linux
- How to use passwd Command in Linux
- How to Create Users using adduser Command in Linux
- Linux File Permission Change by chmod Command in Linux
- How to Use tar Command in Linux